Java, Software Development, Spring Boot

Quickly Create a Spring Boot JPA Application

Creating a new Spring Boot application that uses JPA is easy, straightforward,  and does not involve complex configuration of any kind. You may have worked on other Spring Boot applications which you didn’t develop from scratch. Chances are those applications have a litter of custom configurations. But how do we quickly create a Spring application to work with JPA that is devoid of clutter?

This post uses Spring Initializr and Maven to create initial codes for a Spring Boot JPA application. Moreover,  it uses MySQL, which we could set up locally or run as a docker container to test with the Spring Boot application.

Create a Spring Boot JPA application With Spring Initializr

The best way to quickly create a Spring Boot application that uses JPA is using Spring Initializr. Doing so enables us to compose the application swiftly by choosing relevant starter (and regular) dependencies. Also, the step allows us to generate project files automatically and with ready-to-run Java codes.

With Spring Initializr, we would only need two dependencies – the Spring Data JPA and the JDBC driver for whichever RDBMS we intend to use, e.g., MySQL.

On the other hand, the manual alternative may not be favorable because we would not have the initial complete list of dependencies. Meanwhile, creating new codes from existing Spring Boot applications may require manual changes by stripping off dependencies we don’t need in the new codebase.

How Does Our pom.xml Look?

When we generate the project files via the Spring Initializr, the pom.xml will have three dependencies – two are of our choosing, and another one (the spring-boot-starter-test) which the Spring Initializr includes by default.

Other Files In The Spring Boot JPA Application

Aside from the pom.xml file, we also get the main Java file and an empty application.properties file.

Spring Boot Application Database Configuration

Lastly, we need to modify the empty application.properties file with the following settings.

That’s how we can quickly create a Spring Boot application that uses JPA and with the minimum possible files and configuration.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like