3 回答

TA貢獻1911條經驗 獲得超7個贊
根據 Spring Boot Document(下面的層次結構),我們可以說這@Configuration是其中的一部分@SpringBootConfiguration最終有@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 {
}
@配置
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
}

TA貢獻1909條經驗 獲得超7個贊
SpringBoot配置
表示一個類提供了 Spring Boot 應用@Configuration??梢杂米?Spring 標準@Configuration注釋的替代方法,以便可以自動找到配置(例如在測試中)。應用程序應該只包含一個@SpringBootConfiguration并且大多數慣用的 Spring Boot 應用程序將從@SpringBootApplication繼承它。
來源

TA貢獻1841條經驗 獲得超3個贊
根據 Spring 文檔,
@SpringBootConfiguration
它只是 Spring 標準@Configuration
注釋的替代方法。兩者之間的唯一區別是@SpringBootConfiguration
允許自動找到配置。這在編寫測試時特別有用。
https://www.javacodegeeks.com/2019/09/springbootconfiguration-annotation-spring-boot.html
添加回答
舉報