Creating a custom Spring Boot autoconfiguration starter
We have a high-level idea of the process by which Spring Boot decides which configurations to include in the formation of the application context. Now, let's take a stab at creating our own Spring Boot starter artifact, which we can include as an autoconfigurable dependency in our build.
In Chapter 21, Configuring Web Applications, you learned how to create database Repository
objects. So, let's build a simple starter that will create another CommandLineRunner
that will take the collection of all the Repository
instances and print out the count of the total entries for each.
We will start by adding a child Gradle project to our existing project that will house the codebase for the starter artifact. We will call it db-count-starter
.
How to do it...
- We will start by creating a new directory named
db-count-starter
in the root of our project. - As our project has now become what is known as a
multiproject
build, we will need to create asettings...