Building a custom Spring Boot Starter - From theory to practice
Introduction
Spring Boot starters are key feature of the Spring Boot ecosystem. They simplify dependency management and auto — configuration. A starter mix of dependencies and auto — configuration.It provides specific features with little setup needed. Spring Boot offers many official starters. However, you may need to create a custom starter for reusable functionality across different projects.
In this guide, we’ll look at the theory and practice fo building a custom Spring Boot starter. We’ll learn how to start working under the hood and create a real — world example that you can use as template for you own custom starter.
Understanding Spring Boot starter
What is a Spring Boot starter?
A Spring Boot starter is a special type of module that serves two primary purposes:
- Provide a curated set of dependencies that integrate smoothly with one another.
- Offers auto — configuration capabilities to enable specific functionaility with minimal configuration.
Key components of a custom starter
A typical custom starter consists of the following components:
- Autoconfigure module: contains the auto-configuration code and condition — based configuration.
- Starter module: Alightweight module. It includes the autoconfigure module and the necessary dependencies.
- Properties class: Defines configurable properties for your starter.
- Configuration class: Contains the actual beams and configuration logic.
Naming conventions
Spring Boot has specific naming conventions for custom starters:
- Autoconfigure module:
{name}
-spring-boot-autoconfigure. - Starter module:
{name}
-spring-boot-starter - Don’t start you module name with spring boot unless you’re contributing to the Spring Boot project