0

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'
}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.