Why Spring Boot 2.0 application does not run schema.sql?

Đorđe Pržulj :

While I was using Spring Boot 1.5, on application startup Hibernate executed schema.sql file located in /resources folder when appropriate configuration is set. After Spring Boot 2.0 release this feature does not work any more. I couldn't find anything about this change in documentation. Here is my application.properties file content:

spring.datasource.url=...
spring.datasource.username=...
spring.datasource.password=...

#spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

Is there some change in Spring Boot 2.0 or is this an bug/issue?

Evgeni Dimitrov :

Check the documents here.

In a JPA-based app, you can choose to let Hibernate create the schema or use schema.sql, but you cannot do both. Make sure to disable spring.jpa.hibernate.ddl-auto if you use schema.sql.

You have spring.jpa.hibernate.ddl-auto=create-drop that's why schema.sql is not executed. Looks like this is the way Spring Boot works.

Edit

I think that the problem(not really a problem) is that your application points to a mysql instance.

See the current Spring Boot properties:

spring.datasource.initialization-mode=embedded # Initialize the datasource with available DDL and DML scripts.

The default value is embedded - e.g. initialize only if you're running and embedded database, like H2.

Also see the answer of Stephan here. He said:

Adding spring.datasource.initialization-mode=always to your project is enough.

So try to set:

spring.datasource.initialization-mode=always

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

H2 Schema Empty in Spring Boot Application

Spring Boot application with a jar dependency does not run after maven build

Does every spring boot application create a tomcat container to be able to run?

SQL query returns void in Spring Boot application but does not in H2

Spring boot. Run SQL scripts and get data on application startup

Problems connecting Cloud Run Application to Cloud SQL using Spring boot

Why does my Spring Boot web app not run completely in Gradle?

Spring Boot fails to run schema.sql with dependency on spring-cloud-starter-config

Set schema name at run time using REST API input in spring boot based application

Why spring boot batch application does not print to console?

why spring boot does not load application yml when packaged (With gradle)?

Why AOP does not work in my Spring Boot application?

Spring Boot Application cannot run integration tests for 2 controllers

tests for spring boot application are not run

Run spring boot application on server

Application run failed in Spring Boot

Spring Boot Application run failed

How to see the schema sql (DDL) in spring boot?

Why is my Spring application run from my spring boot unit test

Spring Boot schema.sql - drop db schema on restart

Spring boot 2 hibernate multiple schema

H2 DB in Spring Boot Hibernate does not generate Db Schema

How to run spring-boot as a client application?

Run spring-boot application on Liberty Server

Spring-Boot application run configurations with VScode

Unable to run web application using spring boot

Spring Boot application run method periodically

Initial amount of memory to run a Spring Boot application

Spring Boot Application jar failed to run