开启自动解析配置类
都可以实现配置类分组, DeferredImportSelector可以实现延迟加载配置类上bean
也可以利用@Conditional来自定义条件注解。
例如引入spring-boot-starter-web依赖, 会自动解析Tomcat配置类, 利用条件注解实现
@Configuration
@ConditionalOnClass({Servlet.class, Tomcat.class, UpgradeProtocol.class})
@ConditionalOnMissingBean(
value = {ServletWebServerFactory.class},
search = SearchStrategy.CURRENT
)
public static class EmbeddedTomcat {
public EmbeddedTomcat() {
}
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory() {
return new TomcatServletWebServerFactory();
}
}