spring – What is the difference between @SpringBootConfiguration vs @Configuration?
spring – What is the difference between @SpringBootConfiguration vs @Configuration?
According to Spring Boot Document (hierarchy below), we can say that @Configuration
is a part of @SpringBootConfiguration
which ultimately have @SpringBootApplication
@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 {
}
SpringBootConfiguration
Indicates that a class provides Spring Boot application @Configuration. Can be used as an alternative to the Springs 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
spring – What is the difference between @SpringBootConfiguration vs @Configuration?
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