Skip to main content
PreparationZone Logo
PrepZone

@SpringBootApplication and Friends

The annotations that bootstrap your app and what each one actually enables.

Pass checkpoint below

Why this matters

  • Knowing what each meta-annotation does lets you troubleshoot startup issues — like beans not being found or unwanted auto-config loading.
  • Boot-specific annotations (@ConditionalOn*, @ConfigurationProperties) are the vocabulary for custom starters and library integration.
  • Interview questions often ask what @SpringBootApplication actually contains.

@SpringBootApplication composition

L1 · Fresher

Combines @Configuration, @EnableAutoConfiguration, and @ComponentScan. That trio is why BookStore starts with one annotation on the main class.

@EnableAutoConfiguration

L2 · Intermediate

Imports auto-config classes from META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Your @Bean methods override defaults via @ConditionalOnMissingBean.

Excluding auto-config

L3 · Advanced

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) disables specific configs — use when swapping JPA for JDBC or running slice tests without a database.

scanBasePackages tuning

L4 · Expert

Narrow scan packages in large monorepos to avoid picking up unrelated @Component classes. Pair with @Import for modular configuration without broad scans.

Classpath scanFind @AutoConfiguration classes
@Conditional checksOnClass, OnBean, OnProperty
Register beansOnly if conditions pass
Boot checks classpath and existing beans before creating defaults.

Decomposing @SpringBootApplication

Java
// learn:fragment
@SpringBootApplication
public class BookStoreApplication { ... }

Expands to three annotations:

Java
@SpringBootConfiguration   // alias for @Configuration
@EnableAutoConfiguration   // load auto-config classes from META-INF
@ComponentScan             // scan current package and below

Each serves a distinct purpose in the startup sequence.

Core bootstrap annotations

  • @SpringBootConfiguration — Marks the class as a source of @Bean definitions; typically only on the main class.
  • @EnableAutoConfiguration — Imports AutoConfigurationImportSelector which loads conditional config from META-INF/spring/.
  • @ComponentScan — Discovers @Component, @Service, @Repository, @Controller in the package tree.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 7 sections

  • Customising the scan root
  • @Configuration and @Bean
  • Conditional annotations preview
  • @ConfigurationProperties
  • Web layer annotations
  • Transaction and caching annotations
  • Testing annotations

Test yourself

Answer these before moving on — recall is what makes it stick.