What is a Starter in Spring Boot?
Starters can pull unnecessary transitive dependencies. If you need a minimal classpath (GraalVM Native Image) - use
Junior Level
Starter is a ready-made set of dependencies for specific functionality.
Without Starter:
<!-- Need to add 5+ dependencies manually -->
<dependency><groupId>org.springframework</groupId>...</dependency>
<dependency><groupId>org.hibernate</groupId>...</dependency>
...
With Starter:
<!-- One dependency - everything works! -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Popular starters:
spring-boot-starter-web-> REST APIspring-boot-starter-data-jpa-> Databasesspring-boot-starter-test-> Testing
Middle Level
Starter Architecture
mylib-spring-boot-starter
-> mylib-autoconfigure (configuration)
-> @ConditionalOnClass(...)
-> @Bean methods
-> mylib (main library)
Naming Convention
spring-boot-starter-* -> Official starters
*-spring-boot-starter -> Third-party starters
BOM (Bill of Materials)
<!-- Manages versions of all dependencies -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
</parent>
-> No "Jar Hell" -> all versions are compatible
spring-boot-dependencies is a parent POM with
<dependencyManagement>that fixes versions of hundreds of libraries. You inherit it via<parent>or import it into your<dependencyManagement>.
Customization
# Starter provides default settings
# You can override via application.yaml
mylib:
enabled: true
timeout: 5000
Senior Level
Starter Limitations
Starters can pull unnecessary transitive dependencies. If you need a minimal classpath (GraalVM Native Image) - use <exclusions> or add dependencies manually.
Creating Your Own Starter
// In autoconfigure module:
@AutoConfiguration
@ConditionalOnClass(MyService.class)
@ConditionalOnMissingBean(MyService.class)
public class MyLibAutoConfiguration {
@Bean
public MyService myService() {
return new MyService();
}
}
// Spring Boot 2.7+: META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
// Before 2.7: META-INF/spring.factories
com.example.MyLibAutoConfiguration
ConfigurationProperties
@ConfigurationProperties("mylib")
public class MyLibProperties {
private boolean enabled = true;
private int timeout = 5000;
}
-> IDE auto-completion from spring-configuration-metadata.json
Native Image Support
Spring Boot 3 + GraalVM:
-> Hint files for reflection
-> AOT compilation
-> Starter should support Native Image
Production Experience
Real scenario: corporate starter
50 microservices -> same logging configuration
-> Created mycompany-logging-starter
-> All services got a unified log format
Best Practices
- Separate autoconfigure and starter modules
- @ConditionalOnMissingBean -> allow overriding
- Naming -> *-spring-boot-starter for third-party
- BOM -> version management
- ConfigurationProperties -> YAML configuration
- Native Image -> GraalVM support
Summary for Senior
- Starter = dependencies + auto-configuration
- BOM -> compatible versions
- @ConditionalOnMissingBean -> overriding
- Naming -> *-spring-boot-starter for third-party
- ConfigurationProperties -> YAML configuration
- Native Image -> support in Spring Boot 3
Interview Cheat Sheet
Must know:
- Starter = one dependency instead of many transitive dependencies
- spring-boot-dependencies (BOM) fixes versions of all libraries - no “Jar Hell”
- Starter = autoconfigure module (@ConditionalOnClass, @Bean) + dependencies
- @ConditionalOnMissingBean allows users to override beans
- Third-party starters named -spring-boot-starter, official - spring-boot-starter-
- ConfigurationProperties gives YAML configuration and IDE auto-completion
- Your own starter: @AutoConfiguration + META-INF/spring/…AutoConfiguration.imports (Spring Boot 2.7+)
Common follow-up questions:
- How to create your own starter? - Autoconfigure module with @AutoConfiguration + registration in AutoConfiguration.imports.
- Why is BOM needed? - Fixes compatible versions of hundreds of libraries via dependencyManagement.
- Can you override a bean from a starter? - Yes, via @ConditionalOnMissingBean - your bean replaces the default.
- What to do with unnecessary transitive dependencies? - Use
in Maven or assemble classpath manually for GraalVM.
Red flags (DO NOT say):
- “Starter is just a jar with dependencies” - no, there is also auto-configuration.
- “You can name your starter spring-boot-starter-*” - reserved for official ones.
- “BOM is a regular dependency” - no, it is dependencyManagement for versions.
- “Starters work without auto-configuration” - without it, it is just a set of dependencies.
Related topics:
- [[21. How SpringBootApplication works]]
- [[24. What is a Configuration class]]
- [[29. What are profiles in Spring]]
- [[26. What does the Autowired annotation do]]