Book Image

Spring Boot Cookbook

By : Alex Antonov
Book Image

Spring Boot Cookbook

By: Alex Antonov

Overview of this book

Table of Contents (15 chapters)
Spring Boot Cookbook
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Automatically configuring the database schema and populating it with data


Earlier in the book, in Chapter 2, Configuring Web Applications, we manually added a few entries to the database in the StartupRunner's run(…) method. While doing so programmatically can be a quick and easy way to get something going very quickly, in the long run, it is not really a good idea to do so—especially when you are dealing with a large amount of data. It is also a good practice to separate the database preparations, changes, and other configurations from the rest of the running application code, even if it is setting up the test cases. Thankfully, Spring has provided you with the support to make this task fairly easy and straightforward to solve.

We will continue with the state of the application as we had left it in the previous recipe. Spring provides us with a couple of ways to define how both the structure and data should be populated in the database. The first way relies on using Hibernate to automatically...