SpringBoot入門(6)- @EnableXXX 註解的工作原理
1、@EnableConfigurationProperties –是用來啟用一個特性,可以把配置檔案屬性注入到bean的屬性中(@EnableConfigurationProperties :@ConfigurationProperties)
2、@EnableAsync在類上啟用非同步呼叫,
在介面上使用@Async註解,或在類上使用@Async註解
(@EnableAsync:@Async)
3、@EnableXX內部工作原理就是 @Import匯入一個或多個配置
4、@Import
@Import(User.class)可以引入多個普通bean ---表示被Spring容器託管
@Import(Config.class)可以匯入配置類替代@Configuration ---配置的bean都會被Spring容器所託管
5、ImportSelector介面---內部匯入選擇裝配
作用:selectorImports方法的返回值必須是class全名,該class被spring容器託管
selectorImports方法可以拿到註解的想起資訊進行管理
(註解指的是使用了該ImportSelector的註解下的屬性)
6、ImportBeanDefinitionRegistrar介面
實現該介面可以註冊bean到spring容器進行管理
7、@Import中匯入的class能拿到@EnableXX註解的屬性
例如:
@Import(OutputLog.class)
Public @Interface EnableXX{
String name();
}
在OutputLog中實現ImportSelector或者BeanPostProcessor可以拿到
EnableXX的屬性name的值
@EnableXX的工作原理實際上就是通過@Import匯入指定的配置檔案或bean裝配到spring容器