@SpringBootConfiguration is a specialised form of @Configuration that marks a class as the primary configuration of a Spring Boot application. It behaves like @Configuration (you can declare @Bean methods), but it also lets Spring Boot's test support locate your application configuration automatically.
You rarely write it yourself. It is already included in @SpringBootApplication, so the main class carries it implicitly.
The annotation is declared in org.springframework.boot and is itself meta-annotated with @Configuration:
Because @SpringBootApplication is meta-annotated with @SpringBootConfiguration, annotating your main class with @SpringBootApplication gives you all of its behaviour.
At runtime, both create a configuration class whose @Bean methods are processed the same way. The difference is intent and discoverability.
| Aspect | @Configuration | @SpringBootConfiguration |
|---|---|---|
| Defined in | Spring Framework | Spring Boot |
| Purpose | Any bean configuration class | The single primary configuration of the app |
| Number per application | As many as you want | Should be one |
| Used by test support | No | Yes, searched for by @SpringBootTest and slice tests |
When you write @SpringBootTest or a slice such as @WebMvcTest or @DataJpaTest without naming a configuration class, Spring Boot searches upward from the test's package until it finds a class annotated with @SpringBootConfiguration. That class is used to bootstrap the test context.
If none is found, you get the error Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...). This often happens when the test is in a package that is not under the main class's package or when a library module has no application class. Fix it by moving the test, adding a configuration class, or specifying classes.
Since it is a @Configuration, you can add @Bean methods directly to the main class, although dedicated configuration classes keep the main class small:
Using @SpringBootConfiguration alone, without @EnableAutoConfiguration and @ComponentScan, gives you a configuration class but no auto-configuration or scanning. This is useful in libraries or slim test setups:
The proxyBeanMethods attribute (default true) controls whether @Bean methods are proxied so that calls between them return the same singleton. Setting it to false avoids CGLIB subclassing and reduces startup time, but then bean methods must not call each other to get dependencies; take them as method parameters instead. Because it is aliased, you can also set it through @SpringBootApplication(proxyBeanMethods = false).
@SpringBootApplication class in a sub-package, for example for a demo tool, may be picked up by component scanning and cause duplicate configuration.@SpringBootConfiguration with @TestConfiguration is a different matter: @TestConfiguration classes add beans to a test and are not used for discovery.No. @SpringBootApplication already includes it.
Avoid it. Tests search for one and may fail with an ambiguity error if they find several in the same scope.
It is a specialisation. Use plain @Configuration for additional configuration classes and keep @SpringBootConfiguration for the application entry point.
@SpringBootConfiguration is @Configuration with a Spring Boot role: it identifies the primary application configuration, which Boot's test support uses to build the context. You normally get it for free through @SpringBootApplication; keep exactly one and place it at the root of your package structure.