Learn how to conceptually understand the Spring Boot Starter for bundling dependencies.
- In this chapter, we will see how to create a Spring Boot Microservice with Spring Initializr. To build a Java application, the first step is to create a Java project. Most Java projects rely on third-party Java archive dependencies, and these third-party archives usually have dependencies of their own. On top of that, each version of the dependencies rely on other versions. Managing all these dependencies is a nightmare that Java developers have nicknamed JAR hell.
To avoid JAR hell, we use build dependency management systems like Maven or Gradle. But even with Maven and Gradle, versioning between individual .jar files can be a nuisance. Spring Boot recognizes this, and created the notion of a Spring Boot Starter, which bundles several dependencies into a grouping that is easier to manage. There are a lot, and I mean a lot of Spring Boot Starter dependencies so even cobbling together a project on your own can be difficult.
This is where Spring Initializr comes to the rescue. Spring Initializr is a tool for creating Spring Boot Java projects by answering a series of questions and selecting check boxes to choose which features to include. Initializr creates the package structure, the pom.xml for Maven, or build.gradle for Gradle files, and any required Java source classes. For our first Spring Boot RESTful Microservice, we employ four Spring Boot Starters.
Web, which includes Tomcat and Spring MVC, Rest repositories to expose Spring Data repositories over REST, Java Persistence API, and H2 in memory database driver. To simplify configuration of our first Spring Boot application, we will use an in memory database H2. After answering all of the questions and selecting the desired dependencies, Spring Initializr generates the project.
- Setting up the project
- Building, deploying, and launch the microservice
- Declaring Spring Data JPA repository interfaces
- Invoking repositories
- Using Spring Data query methods
- Exposing RESTful APIs with Spring Data REST
- Using the /search resource to invoke query methods
- Paging and sorting
- Declaring a new REST controller
- Creating HTTP methods for creating, reading, updating and deleting persistent data.