Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

spring - data.sql won't execute

I am trying to initialize a database and insert some data using spring boot. According to the documentation, I just need a data.sql file inside the resourses folder to execute my sql initial data, but for some reason my data.sql is being ignored.

Here is my application.properties file:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/urmamma
spring.datasource.username=root
spring.datasource.password=
spring.session.jdbc.initialize-schema=always
#spring.data.jpa.repositories.bootstrap-mode=default
#spring.datasource.data=classpath:data.sql

My data.sql file:

insert into user (id, email, name) values (1, '[email protected]', 'Teobaldo')

dependencies using gradle:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.data:spring-data-rest-hal-explorer'
    implementation 'org.springframework.session:spring-session-jdbc'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'mysql:mysql-connector-java'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}
question from:https://stackoverflow.com/questions/65924918/data-sql-wont-execute

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was missing this config here:

spring.datasource.initialization-mode=always

While reading the documentation I mistook it for the property

spring.session.jdbc.initialize-schema=always

that I already had.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...