Spring Boot Starters and Dependency Management

Difficulty: Beginner

Question

What are Spring Boot starters, and how do they help with dependency management?

Answer

Anyone who worked with older Spring remembers the pain of building a web project. You needed spring-webmvc, Jackson, a validation API, a logging setup, and Tomcat, and each had to be a compatible version. One wrong version and you would spend an afternoon reading a NoSuchMethodError stack trace. Starters exist to eliminate that whole class of problem.

A starter is a convenience dependency descriptor, essentially a pom with no code of its own that pulls in a curated group of libraries for one purpose. Add spring-boot-starter-web and you get Spring MVC, Jackson for JSON, an embedded Tomcat, and validation-related basics all at once. spring-boot-starter-data-jpa brings Spring Data JPA, Hibernate, and a transaction support. spring-boot-starter-security brings Spring Security, spring-boot-starter-test brings JUnit 5, Mockito, AssertJ, and Spring Test, and spring-boot-starter-actuator brings production endpoints. The naming convention is spring-boot-starter-something for official ones, while third parties use something-spring-boot-starter to avoid confusion.

Version alignment is the second half of the story. Your project inherits from spring-boot-starter-parent, or imports the spring-boot-dependencies BOM, which is a Bill of Materials listing tested versions of hundreds of libraries. That is why you write the dependency without a version number and Maven or Gradle picks the one Boot has verified. When you upgrade Boot from 3.2 to 3.3 the whole set of transitive versions moves together consistently. If you must override a version, say for a security fix, you set a property such as jackson-bom.version or specify the version explicitly, understanding that you leave the tested path.

Starters also work together with auto-configuration. The starter puts libraries on the classpath, and auto-configuration notices them and configures beans. That combination is the reason a project goes from empty to a running REST service in a few minutes. Remove the starter and the associated auto-configuration disappears because its class conditions no longer hold.

Practical hygiene worth mentioning: swap the default server by excluding spring-boot-starter-tomcat and adding spring-boot-starter-jetty. Use mvn dependency:tree to see what a starter pulled in when you are chasing a conflict. Avoid adding starters you do not use, since each one increases the startup time, the JAR size, and the attack surface. And do not mix a starter with manually chosen conflicting versions of the same library.

In an interview, tie it together in a sentence: starters give you the right dependencies, the BOM gives you the right versions, and auto-configuration gives you the right beans.

Code examples

Typical pom.xml dependencies

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.4</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>   <!-- no version needed -->
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

Versions come from the parent BOM, so all Spring, Hibernate, Jackson and Tomcat versions stay compatible.

Key points

Common follow-up questions

Interview tips

Concepts covered

Starters, BOM, Maven, Dependency Management

More Spring Boot questions