For Spring Boot 3.1.1
About dependencies is declared:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
In the src/main/resources exists only the following:
src/main/resources
application.properties
application-mysql.properties
Observe there are no .sql files. The application.properties file contains
spring.profiles.active=mysql,cache
The application-mysql.properties file - that must be used for runtime because the mysql profile was declared and the application-{profile}.properties pattern is applied - contains:
spring.datasource.url=jdbc:mysql://192....
spring.datasource.username=root
spring.datasource.password=<something>
spring.sql.init.mode=always
spring.sql.init.platform=mysql
The connection is accomplished and some CRUD operations is executed at peace but ...
but is expected to receive an error/exception at startup due the following:
spring.sql.init.mode=alwaysbecause there is no an in-memory database suchh2andMySQLis used instead, therefore some sql scripts must be executed.spring.sql.init.platform=mysqlis expected to find theschema-mysql.sqlanddata-mysql.sqlfiles atsrc/main/resources, it according with theschema-${platform}.sqlanddata-${platform}.sqlpatterns respectively
Now because the schema-mysql.sql and data-mysql.sql does not exist at src/main/resources is expected an error, but it does not happen. Why? ... Same situation if is declared
spring.sql.init.platform=mysqlabc
I am assuming some Application Property is missing
Consider the use the MySQL and not H2 for pre-production purposes.
schema.sql, or adata.sqlor aschema-mysql.sqland genericdata.sqlall sorts of combinations are possible, then what should be required? Although a warning in the logs could be an improvement if init is enabled but no sql files are actually found.