Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can
“just run”. It is based on a model of Convention over Configuration and good intentions.
Introduction
This is the sixth part part of a series of posts focused on Hibernate and JPA. In my previous post we demonstrated how to write
CRUD functions using interfaces in Spring Data. In this post we will
look at reducing configuration with Spring Boot and writing less boilerplate code.
At the end of this post you will have familiarised yourself with Spring Boot.
To set up a Spring Boot project we need the following dependencies
spring-boot-starter
Modify the pom.xml file by making the following changes:
Wow! That’s a lot of changes. But that will be all for our POM.xml.
Naming Strategy
Hibernate 5 deprecated the legacy NamingStrategy in favour of
ImplicitNamingStrategy and PhysicalNamingStrategy. With the release of Spring Boot 1.4, a new
SpringPhysicalNamingStrategy is auto configured to align with Hibernate 5.
Part of the mapping of an object model to the relational database is mapping names from the object model to the corresponding database names. The SpringPhysicalNamingStrategy uses snake case for the database names. In this regard we will modify our
Liquibase Changelog file.
file: src/main/resources/dbChangelog.xml:
Plumbing
We now made a few minor changes to get Spring Boot up and running.
file: src/main/resources/application.properties:
Spring Boot
Spring Boot is all about reducing the amount of boilerplate code you have to write.
Remove:
Next remove all beans from the Application class and we end up with this:
That’s it.
Conclusion
In this post we did a rewrite of our previous articles in the series to use Spring Boot. We also saw how easy it is to configure a
Spring Boot project.
As usual you can find the full example to this guide in the github repository. Until the next post, keep doing cool things .