@AutoConfigureBefore
在 JtaAutoConfiguration 之前加载
@AutoConfigureBefore({ XADataSourceAutoConfiguration.class, ActiveMQAutoConfiguration.class, ArtemisAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) public class JtaAutoConfiguration { }
@AutoConfigureAfter
与 @AutoConfigureBefore 类似,在之后加载
@Conditional
指定的Condition实现类,matches方法返回true则注入bean,false则不注入
@Bean @Conditional(BootstrapExecutorCondition.class) public EntityManagerFactoryBuilderCustomizer entityManagerFactoryBootstrapExecutorCustomizer(
@ConditionalOnBean
仅仅在当前上下文中存在某个对象时,才会实例化一个 Bean
@ConditionalOnBean(DataSource.class) class JdbcSessionConfiguration {
@ConditionalOnClass
某个class位于类路径上,才会实例化一个Bean,要求指定的class必须存在
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class })public class WebMvcAutoConfiguration {
@ConditionalOnMissingBean
仅仅在当前上下文中不存在某个对象时,才会实例化一个Bean
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)public class WebMvcAutoConfiguration {
@ConditionalOnProperty
matchIfMissing:从 application.properties 中读取某个属性值,如果该值为空,默认值为 true
havingValue:通过其两个属性name以及havingValue来实现的,其中name用来从application.properties中读取某个属性值,如果该值为空,则返回false。
如果值不为空,则将该值与havingValue指定的值进行比较,如果一样则返回true;否则返回false。如果返回值为false,则该configuration不生效;为true则生效。
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)public class JpaRepositoriesAutoConfiguration {
@ConditionalOnMissingClass
某个class类路径上不存在的时候,才会实例化一个Bean
@ConditionalOnMissingClass("org.aspectj.weaver.Advice")static class ClassProxyingConfiguration {
@ConditionalOnExpression
当表达式为true的时候,才会实例化一个Bean
@Configuration @ConditionalOnExpression("${xxx.enabled:false}") public class XxxConfiguration {
@ConditionalOnNotWebApplication
当前不是web应用
@ConditionalOnNotWebApplication class FreeMarkerNonWebConfiguration extends AbstractFreeMarkerConfiguration {
@ConditionalOnWebApplication
当前是web应用
@ConditionalOnWebApplication(type = Type.SERVLET) public class WebMvcAutoConfiguration {
@ConditionalOnResource
类路径下是否存在指定的资源文件
@ConditionalOnResource(resources = "classpath:META-INF/services/javax.validation.spi.ValidationProvider") public class ValidationAutoConfiguration {
@AutoConfigureOrder
Bean加载优先级别根据数字决定,数字越小,越优先加载,负数也可以
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE + 10) public class WebMvcAutoConfiguration {
来源:https://www.cnblogs.com/jhxxb/p/12658141.html