08-02-2023, 02:11 PM
I am working with spring boot 2.6.0
I tried several answers and they were not enough.
One temporal solution I found was this
@SpringBootApplication(exclude = SqlInitializationAutoConfiguration.class)
Although it lets the server run and the h2-console appear I could not connect to my data.sql file. This was the error I got
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149
This is the solution I found
(Some have already been)Add these lines to the application.properties file
spring.jpa.show-sql=true
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.jpa.defer-datasource-initialization=true
Save an re-run the server then try to access the db on the browser again from the h2-console
By default, data.sql scripts are now run before Hibernate is initialized. This aligns the behavior of basic script-based initialization with that of Flyway and Liquibase. If you want to use data.sql to populate a schema created by Hibernate, set spring.jpa.defer-datasource-initialization to true.
spring.jpa.defer-datasource-initialization=true solves the issue
I tried several answers and they were not enough.
One temporal solution I found was this
@SpringBootApplication(exclude = SqlInitializationAutoConfiguration.class)
Although it lets the server run and the h2-console appear I could not connect to my data.sql file. This was the error I got
Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149
This is the solution I found
(Some have already been)Add these lines to the application.properties file
spring.jpa.show-sql=true
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.jpa.defer-datasource-initialization=true
Save an re-run the server then try to access the db on the browser again from the h2-console
By default, data.sql scripts are now run before Hibernate is initialized. This aligns the behavior of basic script-based initialization with that of Flyway and Liquibase. If you want to use data.sql to populate a schema created by Hibernate, set spring.jpa.defer-datasource-initialization to true.
spring.jpa.defer-datasource-initialization=true solves the issue