Reputation: 6285
What is the difference between @SpringBootConfiguration
and @Configuration
? I cannot find much details on it.
Upvotes: 27
Views: 13045
Reputation: 1
@SpringBootConfiguration is mainly for unit test and integration test to automatically find configuration without having you to use @ContextConfiguration and nested configuration class
Upvotes: 0
Reputation: 13807
As per Springboot docs (hierarchy below), @Configuration
is a part of @SpringBootConfiguration
which ultimately has @SpringBootApplication
annotation.
@SpringBootApplication
-------> @SpringBootConfiguration
-------> @Configuration
@SpringBootApplication
Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM,
classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
...}
@SpringBootConfiguration
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
}
@Configuration
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
}
Upvotes: 17
Reputation: 16930
As per the Spring documentation,
@SpringBootConfiguration
is just an alternative to the Spring standard@Configuration
annotation. The only difference between the two is that the@SpringBootConfiguration
allows the configuration to be found automatically.This is specifically useful when writing tests.
https://www.javacodegeeks.com/2019/09/springbootconfiguration-annotation-spring-boot.html
Upvotes: 3
Reputation: 5978
SpringBootConfiguration
Indicates that a class provides Spring Boot application @Configuration. Can be used as an alternative to the Spring's standard @Configuration annotation so that configuration can be found automatically (for example in tests). Application should only ever include one @SpringBootConfiguration and most idiomatic Spring Boot applications will inherit it from @SpringBootApplication.
Source
Documentation on SpringBootConfiguration
Upvotes: 5