@SpringBootApplication — What It Combines
Fast recall
Quick revision
Core answer
@SpringBootApplication is a convenience meta-annotation that combines `@SpringBootConfiguration` (a specialised @Configuration enforced as singleton per context), `@EnableAutoConfiguration` (triggers auto-configuration scanning), and `@ComponentScan` (scans the package of the annotated class and all sub-packages for Spring components). The component scan boundary is the package containing the annotated class — sibling packages are invisible. Use scanBasePackageClasses for refactoring-safe explicit scan paths and exclude = {...} to prevent unwanted auto-configurations.Whether the candidate understands component scanning scope and can explain why placing the main class in the root package matters
Placing the main class inside a sub-package so that sibling packages are missed by `@ComponentScan`, causing beans not to be found
Explain that you can narrow or widen the scan with `scanBasePackages`/`scanBasePackageClasses`, and that `@SpringBootConfiguration` differs from `@Configuration` because only one is allowed per application context
Interview-ready guide
Interview answer
@SpringBootApplication is a single annotation that composes three: @SpringBootConfiguration (this class is a primary bean source enforced as singleton per context), @EnableAutoConfiguration (activate Spring Boot's auto-configuration), and @ComponentScan (scan from this class's package downward).
The scan boundary rule
- The component scan starts from the package containing the
@SpringBootApplicationclass - Place the main class in the root package (
com.example) so every sub-package (com.example.service,com.example.repository) is automatically discovered - A main class buried inside a sub-package means sibling packages are outside the scan boundary — beans there are invisible
Customizing the scan
@SpringBootApplication(scanBasePackages = "com.example")extends the boundary, but string-based — renaming the package breaks it silentlyscanBasePackageClasses = {ServiceMarker.class}is refactoring-safe — a compile error tells you immediately when the marker class moves
Excluding auto-configurations
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})prevents that auto-config from running — useful when a starter pulls in database config you do not want- Type-safe and visible at the annotation site; prefer this over the string-based property approach
Test discovery
@SpringBootTestwalks up from the test class to find one@SpringBootConfiguration- Two configurations cause ambiguous configuration errors
@SpringBootTest(classes = App.class)bypasses auto-discovery when class hierarchies don't align
In an interview, the strong answer is: the three annotations are easy; the test is whether you understand the scan boundary, the singleton constraint, and refactoring-safe scan configuration.
@SpringBootApplication — What It Combines
Direct Answer
@SpringBootApplication is a convenience meta-annotation that combines @SpringBootConfiguration (a specialised @Configuration enforced as singleton per context), @EnableAutoConfiguration (triggers auto-configuration scanning), and @ComponentScan (scans the package of the annotated class and all sub-packages for Spring components). The component scan boundary is the package containing the annotated class — sibling packages are invisible. Use scanBasePackageClasses for refactoring-safe explicit scan paths and exclude = {...} to prevent unwanted auto-configurations.
Common Mistakes & Pitfalls
Placing the main class inside a sub-package so that sibling packages are missed by @ComponentScan, causing beans not to be found
Check your understanding
Answer these without looking back at the article.
- What happens if you have two classes annotated with `@SpringBootConfiguration` in the same context?
- How would you configure component scanning to include a package outside the main application package?
- Can you use `@SpringBootApplication` on a class that is not the entry point main class?
- When would you decompose `@SpringBootApplication` into its three constituent annotations?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.