पाठ 2 / 25

Starters and the Project Layout

Dependencies by capability.

Pick capabilities, not libraries

A starter is a dependency that pulls in a tested set of libraries for one capability: web MVC with an embedded Tomcat, validation, JPA with Hibernate, Actuator, security. The starter parent (or Spring Boot's dependency management) pins compatible versions for hundreds of libraries, so you usually omit versions. In Spring Boot 4 the web starter for servlet apps is spring-boot-starter-webmvc, and each starter has a matching test starter. Code lives under a base package with the @SpringBootApplication class at its root, so component scanning finds everything below it.

Starters in the demo's pom.xml

This file is from a demo "shop" service generated by start.spring.io for Spring Boot 4.1.1 and Java 21 (Temurin 21.0.12), built with Maven 3.9.16; the project compiled and its tests passed. Simplified excerpt; versions come from the parent, so starters list none.

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

<dependencies>
    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webmvc</artifactId></dependency>
    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-validation</artifactId></dependency>
    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency>
    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>
    <dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><scope>runtime</scope></dependency>
    <!-- Boot 4 ships matching test starters, e.g. spring-boot-starter-webmvc-test -->
</dependencies>

Let Boot manage versions

Overriding versions managed by Spring Boot often causes subtle incompatibilities; upgrade Boot instead.

त्वरित जाँच: Why do starters usually omit version numbers?

  • The Spring Boot parent manages compatible versions
  • Versions are optional in Maven always
  • Starters have no versions
  • Maven picks random versions
Answer

The Spring Boot parent manages compatible versions — Dependency management keeps versions aligned.