Quick Guide on loading initial data with Spring Boot

Click for: original source

Spring Boot makes it really easy to manage our database changes in an easy way. If we leave the default configuration, it’ll search for entities in our packages and create the respective tables automatically. By Eugen Paraschiv.

But sometimes we’ll need some finer grained control over the database alterations. That’s when we can use the data.sql and schema.sql files in Spring.

The content of this article:

  • The data.sql file
  • The schema.sql file
  • Controlling database creation using Hibernate
  • @Sql
  • @SqlConfig
  • @SqlGroup

You will learn hwo we can leverage schema.sql and data.sql files for setting up an initial schema and populating it with data. We also saw how we can use @Sql, @SqlConfig, and @SqlGroup annotations to load test data for tests. Keep in mind that this approach is more suited for basic and simple scenarios, any advanced database handling would require more advanced and refined tooling like Liquibase or Flyway. Great read!

[Read More]

Tags java app-development web-development programming