Sub topic 2
What a starter is and what it brings in
This chapter assumes you can create and run a basic Spring Boot application. It also assumes you know what beans and the application context are, and that you can read a Maven or Gradle build file. The previous chapter covered how the Boot parent and BOM supply versions. This chapter builds on that and looks at the dependencies themselves.
What a starter is
A starter is a dependency descriptor. It is a small artifact whose job is to pull in a coherent set of other libraries. Spring Boot's own starters contain no meaningful Java code. Each is essentially a POM (or Gradle module metadata) with a list of dependencies.
Without starters, adding web support means choosing and aligning several libraries yourself: Spring MVC, a servlet container, a JSON library, a logging backend, and the Spring Boot support jars. With a starter, you declare one dependency and the build tool resolves the rest transitively.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>There is no <version> element. The version comes from the Boot parent or BOM, so every library the starter pulls in is one that Boot has tested together.
Starter versus auto-configuration
These two ideas are often confused, so keep them apart.
| Row | Starter | Auto-configuration |
|---|---|---|
| What it is | A dependency descriptor | Java configuration classes |
| What it does | Puts libraries on the classpath | Creates beans based on what is on the classpath |
| When it acts | At build and dependency-resolution time | At application startup |
| Where Boot's own live | `spring-boot-starter-*` artifacts | Mostly in `spring-boot-autoconfigure` |
A starter makes things available. Auto-configuration reacts to what is available. Adding spring-boot-starter-web does not create a web server by itself. It puts Spring MVC and Tomcat on the classpath, and auto-configuration notices them and sets up the beans. The next chapters cover that second step.
What spring-boot-starter-web brings in
The best way to see what a starter does is to ask your build tool. For Maven:
mvn dependency:treeFor Gradle:
./gradlew dependencies --configuration runtimeClasspathFor a project that declares only spring-boot-starter-web, an abridged Maven tree looks like this. Exact artifacts and versions depend on your Boot version, and this sketch follows the Boot 3.x line.
org.springframework.boot:spring-boot-starter-web
+- org.springframework.boot:spring-boot-starter
| +- org.springframework.boot:spring-boot
| +- org.springframework.boot:spring-boot-autoconfigure
| +- org.springframework.boot:spring-boot-starter-logging
| | +- ch.qos.logback:logback-classic
| | +- org.apache.logging.log4j:log4j-to-slf4j
| | \- org.slf4j:jul-to-slf4j
| +- jakarta.annotation:jakarta.annotation-api
| \- org.yaml:snakeyaml
+- org.springframework.boot:spring-boot-starter-json
| \- com.fasterxml.jackson.core:jackson-databind (and related modules)
+- org.springframework.boot:spring-boot-starter-tomcat
| \- org.apache.tomcat.embed:tomcat-embed-core (and related modules)
+- org.springframework:spring-web
\- org.springframework:spring-webmvcThree things stand out.
- Starters nest. The web starter depends on
spring-boot-starter,spring-boot-starter-json, andspring-boot-starter-tomcat. Each of those is itself a starter. - The core starter is shared.
spring-boot-starterappears under almost every other starter. It bringsspring-boot,spring-boot-autoconfigure, logging, and YAML parsing. This is how the auto-configuration jar reaches your classpath even though you never declared it. - The server is a separate starter. Tomcat arrives through
spring-boot-starter-tomcat, not directly. That separation is what makes it replaceable.
Why `spring-boot-autoconfigure` matters here
You normally never depend on spring-boot-autoconfigure yourself. It arrives through spring-boot-starter. That means almost any starter gives you the same set of auto-configuration classes. What changes between starters is which third-party libraries are present, and therefore which of those classes switch on.
Kinds of starters
Boot's official starters fall into loose groups. The grouping is a convention, not something the build enforces.
| Group | Examples | Purpose |
|---|---|---|
| Application starters | `spring-boot-starter-web`, `-data-jpa`, `-security`, `-validation` | Add a feature to your application |
| Technical starters | `spring-boot-starter-tomcat`, `-jetty`, `-undertow`, `-logging`, `-log4j2` | Swap a specific technology |
| Production-ready | `spring-boot-starter-actuator` | Monitoring and management endpoints |
| Test | `spring-boot-starter-test` | JUnit, AssertJ, Mockito, Spring Test |
Application starters are the ones you declare most often. Technical starters usually appear through an application starter, and you touch them only when you want to replace something.
Naming conventions
Names signal ownership.
- Official starters follow
spring-boot-starter-*, for examplespring-boot-starter-data-redis. - Third-party starters should not use that prefix, because it belongs to the Spring Boot project. By convention they use
*-spring-boot-starter, for examplemylib-spring-boot-starter.
Seeing acme-spring-boot-starter in a dependency list tells you it is not maintained by the Boot team.
Replacing a technology: swapping Tomcat for Jetty
Because the server is its own starter, you can exclude it and add another. In Maven:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
</dependencies>In Gradle (Kotlin DSL):
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web") {
exclude(group = "org.springframework.boot", module = "spring-boot-starter-tomcat")
}
implementation("org.springframework.boot:spring-boot-starter-jetty")
}No Java changes are needed. When the application starts, auto-configuration finds Jetty classes instead of Tomcat classes and creates a Jetty-backed server. The same technique swaps Logback for Log4j2: exclude spring-boot-starter-logging and add spring-boot-starter-log4j2.
Starters and scopes
Most starters belong in the default compile scope (implementation in Gradle). Two cases differ.
The test starter should be limited to tests:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>In Gradle, use testImplementation. Without this, JUnit and Mockito end up in your production artifact.
Some starters, such as Tomcat when you build a WAR for an external container, are marked as provided so the container supplies them. The spring-boot-starter-tomcat dependency can be declared with provided scope in that case.
Common errors
A version on a starter
Writing <version> on a Boot starter overrides the managed version. For a starter that is usually wrong, because its transitive libraries are still the ones Boot manages, and you now have a starter that disagrees with the rest. Remove the version and let the parent or BOM decide. If you need a different Boot release, change the parent version.
Adding a starter whose beans need configuration
A starter can pull in a library whose auto-configuration cannot work without your input. The classic example is spring-boot-starter-data-jpa without a database driver or URL. Startup fails with a message such as Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. The starter did its part, and auto-configuration then tried to build a DataSource and could not. The fix is to add a driver and set spring.datasource.url, or to remove the starter if you do not need it.
Mixing web stacks
spring-boot-starter-web (Spring MVC) and spring-boot-starter-webflux (reactive) can coexist on one classpath. In that case Boot configures a Spring MVC application, and WebFlux is used only for its WebClient. If you wanted a reactive server, remove the web starter.
Unused starters
Each starter you add enlarges the classpath and can switch on extra auto-configuration. A leftover spring-boot-starter-security, for instance, secures every endpoint by default. If behavior surprises you after a dependency change, inspect the tree first.
Summary of the working model
- A starter is a dependency descriptor. It puts a curated, version-aligned set of libraries on the classpath.
- Starters nest, and nearly all of them reach
spring-boot-starter, which bringsspring-boot-autoconfigure. - Technology choices such as the server or logging backend sit in their own starters, so you replace them by exclusion.
- Starters do not create beans. Auto-configuration does, by reacting to what the starters put on the classpath.
The next chapter looks at @SpringBootApplication, the annotation that turns that reaction on.
Exercise
A project declares only spring-boot-starter-web. You run the dependency tree and find that Tomcat is present, although the project never mentions it. Explain where it came from, and list the steps to run on Jetty instead.
Show answer
Tomcat arrives transitively. spring-boot-starter-web depends on spring-boot-starter-tomcat, which depends on the embedded Tomcat libraries. To use Jetty, add an exclusion for spring-boot-starter-tomcat inside the spring-boot-starter-web dependency, then add spring-boot-starter-jetty as a separate dependency. No code changes are required, because auto-configuration builds a server from whichever one is on the classpath.
Exercise
A teammate says that adding spring-boot-starter-data-jpa "configures JPA." Using the starter versus auto-configuration distinction, correct the statement. Then explain why the application might fail at startup after only that dependency is added.
Show answer
The starter only adds libraries such as Hibernate and Spring Data JPA to the classpath. The auto-configuration classes in spring-boot-autoconfigure, which arrive through spring-boot-starter, detect those libraries and try to create the JPA beans. Startup can fail because the auto-configuration needs a DataSource, and without a JDBC driver and a spring.datasource.url there is none, giving a "Failed to configure a DataSource" error.
Exercise
Which artifact name would you expect for a third-party starter from a company called Acme, and why should it not start with spring-boot-starter?
Show answer
acme-spring-boot-starter. The spring-boot-starter-* prefix is reserved for starters maintained by the Spring Boot project, so third parties put their name first to avoid implying official ownership.