Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Spring Boot Starters  ›  Lesson

What a Starter Is

Spring Boot Starters 10 minA starter is a dependency that brings a tested set of libraries for one feature, which auto-configuration then sets up.

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 as spring-boot-starter-web.
  • Third-party starters put their own name first, <project>-spring-boot-starter, such as mybatis-spring-boot-starter. The spring-boot prefix is reserved for the Spring team.

The same starters work with Gradle:

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
}

The shortcut

When you need a feature, don't list libraries; name the feature and look for its starter. Then check that auto-configuration picked it up by starting the app and reading the log.

Adding input validation to library-serviceStep 1 of 4
  1. Name the feature

    Reject a new Book whose title is blank.

The trap is adding the underlying libraries by hand next to a starter, each with its own version. You end up with two versions of one library on the classpath, and the resulting errors are hard to trace. Let the starter decide.

Drills

Answer fast — trust the rule.

quick drill

What does a Spring Boot starter mainly contain?

quick drill

Which of these does spring-boot-starter-web bring?

quick drill

A company writes its own starter for an internal audit library. What should it be called?

quick drill

After adding a starter, what makes Spring create the beans the new libraries need?

Remember

  • One starter, one feature: it brings the libraries, Boot brings the setup.
  • Name the feature, find its starter, then confirm in the startup log.
  • Trap: adding the starter's libraries again by hand with their own versions.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainStarter or libraries?

A colleague wants to add Spring MVC, Jackson and Tomcat to a Boot project as three separate dependencies with hand-picked versions. Explain what you would do instead and why, and how the app knows to start a web server afterwards.