Yunus Einsteinium
Yunus Einsteinium

Reputation: 1180

Preload Springboot application with data

I have a Spring Boot application and I need it to populate users table with an admin account during database initialization as root account.

Checking around the web, I am told to make sure I have this in my application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/dbname?createDatabaseIfNotExist=true
spring.datasource.username=root
spring.datasource.password=

spring.jpa.generate-ddl= true
spring.jpa.hibernate.ddl-auto= update
spring.datasource.initialize=true
spring.jpa.hibernate.dialect= org.hibernate.dialect.MySQL5Dialect

I also have data.sql in resourses folder with following SQL statement

INSERT INTO users (username, password) VALUES ('admin', '$shiro1$SHA-256$500000$FkZcH5hP9oiYkP6UBK/84Q==$RHFwVRYTKNnCpKtlOu3Nfts8I+3Azfw5iUWokmW0dgI=')

When I run the app, this data is not inserted into the users table

Update

I have this Github repo for demonstration.

Upvotes: 1

Views: 1269

Answers (1)

Miloš Milivojević
Miloš Milivojević

Reputation: 5369

You have to have a schema.sql file too, and it cannot be empty; it is a hack but you can create a schema.sql with the following content:

SELECT 1;

And everything should work correctly.

Refer to the official documentation for more details.

Upvotes: 1

Related Questions