Sub topic 3
Starters: Curated Dependency Sets
This chapter assumes you can read a Maven pom.xml (or a Gradle build file), know what a transitive dependency is, and have seen the Spring Boot overview from the previous chapters. After it, you should be able to read a starter declaration, predict what ends up on the classpath, and change that on purpose.
The problem starters solve
A plain Spring web application needs many libraries that must work together. These include Spring MVC, a servlet container, a JSON library, a logging framework, and validation. Without starters, you pick each library, choose a version, and check that the versions are compatible. A wrong guess shows up at runtime as a NoSuchMethodError or a ClassNotFoundException.
A starter is a dependency descriptor that stands for a capability instead of a single library. When you add spring-boot-starter-web, you are saying "this is a web application". Maven then pulls in the libraries that capability needs.
What a starter is, mechanically
A starter is an ordinary Maven artifact. Its JAR is essentially empty. Its pom.xml lists other dependencies, and your build resolves those as transitive dependencies. A starter has no magic of its own.
Here is a typical dependencies block:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>Neither entry has a <version>. The Spring Boot parent POM supplies versions, as the section on version management below explains.
The web starter brings in these main pieces:
| Transitive piece | Purpose |
|---|---|
| `spring-boot-starter` | Core Boot, auto-configuration support, logging, YAML parsing |
| `spring-boot-starter-json` | Jackson, for converting objects to and from JSON |
| `spring-boot-starter-tomcat` | The embedded Tomcat server |
| `spring-web`, `spring-webmvc` | The Spring MVC web framework |
The test starter brings in JUnit Jupiter, Spring Test, Spring Boot Test, AssertJ, Hamcrest, Mockito, JSONassert, and JsonPath. The test scope keeps all of it out of your packaged application.
Seeing what you actually get
Do not trust a list in a book, including this one. Ask the build tool:
./mvnw dependency:treeThe output is a tree with your starters at the top level and their transitive dependencies below them. Run it after every change to the dependencies. Gradle users can run ./gradlew dependencies --configuration runtimeClasspath.
Naming conventions
Starters follow a naming pattern that tells you who owns them.
| Pattern | Owner | Example |
|---|---|---|
| `spring-boot-starter-*` | The Spring Boot team | `spring-boot-starter-data-jpa` |
| `*-spring-boot-starter` | Third parties | `mybatis-spring-boot-starter` |
The reversed order for third parties is deliberate. The spring-boot prefix is reserved for official artifacts.
Some commonly used official starters:
spring-boot-starter-web: REST APIs and MVC web applications on Tomcat.spring-boot-starter-data-jpa: Hibernate and Spring Data JPA.spring-boot-starter-validation: Bean Validation with Hibernate Validator.spring-boot-starter-security: Spring Security.spring-boot-starter-actuator: production monitoring endpoints.spring-boot-starter-test: the testing toolkit.
How versions stay consistent
You wrote no versions, yet the build resolves specific ones. The mechanism lives in your parent POM. A project generated by Spring Initializr declares:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/>
</parent>spring-boot-starter-parent inherits from spring-boot-dependencies. That POM is a BOM (bill of materials), a large dependencyManagement section that fixes the version of hundreds of libraries. When you declare a dependency without a version, Maven looks it up in that table.
The Boot version is therefore the single version number you choose. Upgrading Boot upgrades the whole tested set of libraries together.
The parent also sets some build defaults, such as UTF-8 encoding and the Java release level from the java.version property. It also configures the Boot Maven plugin.
Gradle projects get the same result from the Spring Boot Gradle plugin together with the io.spring.dependency-management plugin:
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.0'
id 'io.spring.dependency-management' version '1.1.6'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}If you cannot use spring-boot-starter-parent because your organization requires its own parent POM, import the BOM instead. Add spring-boot-dependencies with <type>pom</type> and <scope>import</scope> inside your own dependencyManagement block.
Overriding a managed version
Sometimes you need a different version, for example to pick up a security patch before the next Boot release. The BOM exposes version properties, and you override the property in your POM:
<properties>
<java.version>21</java.version>
<jackson-bom.version>2.18.2</jackson-bom.version>
</properties>The property names are listed in the Boot reference documentation under dependency versions. Override sparingly. You are leaving the tested combination, and you become responsible for compatibility.
Customizing a starter's contents with exclusions
A starter is a default choice, and you can change it. The standard example is replacing Tomcat with Jetty. You exclude the Tomcat starter from the web starter and add the Jetty starter:
<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>Your controller code does not change, because it depends on Spring MVC and not on the server. The next chapters cover the embedded server in detail.
Starters and auto-configuration
Starters decide what is on the classpath. Auto-configuration looks at the classpath and decides which beans to create. The two features work as a pair.
For example, spring-boot-starter-web puts Jackson on the classpath. Boot's JSON auto-configuration then notices Jackson and registers an ObjectMapper bean. Add spring-boot-starter-data-jpa plus a database driver, and Boot configures a DataSource and an EntityManagerFactory. Remove the starter, and those beans vanish.
This means adding a dependency changes application behavior even when you write no code. That is useful, but it can surprise you.
Common errors and gotchas
- Missing starter, missing feature. If
@RestControlleris not found or the application starts and exits at once, check that the web starter is present. Without a web starter, Boot starts a plain application with no server. - Two servers on the classpath. Adding the Jetty starter without excluding Tomcat leaves both present. Boot picks one by its own ordering, which may not be the one you intended. Check
dependency:tree. - Hand-picked versions on managed libraries. An explicit version that disagrees with the BOM can cause runtime errors. Only specify versions for libraries the BOM does not manage.
- Starter bloat. Each starter adds JARs and auto-configuration. Adding
spring-boot-starter-data-jpawithout a database causes a startup failure, because Boot cannot find aDataSource. Add only what you use. - Test dependencies in compile scope. Leaving out
<scope>test</scope>ships JUnit and Mockito in your production JAR. - Mixing Boot versions. Do not combine starters from different Boot versions. Let the parent or BOM supply every Boot artifact.
When to write your own starter
Teams that share code across many services sometimes build an internal starter. By convention it is two modules: an auto-configuration module that holds the beans and conditions, and a starter module that only depends on it and on the needed libraries. This is worth doing only when several applications need identical setup. For one project, a normal configuration class is simpler.
Exercise
Your POM declares spring-boot-starter-web with no version, and the build still resolves Jackson at a specific version. Where does that version come from, and how would you move Jackson to a newer release in a way that keeps its related modules aligned?
Show answer
The version comes from the spring-boot-dependencies BOM, which spring-boot-starter-parent inherits (or which you import). Override the BOM's version property, such as jackson-bom.version, in the <properties> section of your POM. This changes the whole Jackson library family together, which a version on one individual dependency would not.
Exercise
You add spring-boot-starter-jetty to a project that already has spring-boot-starter-web, and dependency:tree shows both Tomcat and Jetty. What step is missing, and which command shows you the result?
Show answer
The Tomcat starter must be excluded from spring-boot-starter-web with an <exclusion> for spring-boot-starter-tomcat. After the change, run ./mvnw dependency:tree and confirm that Tomcat no longer appears.