What a Starter Is
Before Spring Boot, adding a REST API to a project meant hunting down a dozen libraries: Spring MVC, a JSON library, a servlet container, a validation library, and a version of each that worked with all the others. One wrong version and the app failed at startup with an error nobody could explain. Starters replaced that hunt with a single line.
The rule
One starter, one feature: it brings the libraries, Boot brings the setup.
A starter is a dependency that contains almost no code of its own. Its job is to pull in a tested set of other libraries for one feature. For library-service's REST API:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>That one entry brings Spring MVC, Jackson for JSON, an embedded Tomcat server, and logging. You write no version number and no glue code.
Starters work hand in hand with auto-configuration (the next section). The starter puts libraries on the classpath; auto-configuration notices them and creates the beans they need. So adding spring-boot-starter-web is enough for the app to start a web server on port 8080 and serve your @RestControllers.
The name tells you who made it:
- Official starters are named
spring-boot-starter-<feature>, such asspring-boot-starter-web. - Third-party starters put their own name first,
<project>-spring-boot-starter, such asmybatis-spring-boot-starter. Thespring-bootprefix is reserved for the Spring team.
The same starters work with Gradle:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}