【SpringBoot】SpringBoot 配置这一篇文章就够了 (7)

作用:必须是@Conditional指定的条件成立,才给容器中添加组件,配置文件中的内容才生效

@Conditional扩展注解 作用(判断是否满足当前指定条件)
@ConditionalOnJava   系统的java版本是否符合要求  
@ConditionalOnBean   容器中存在指定Bean;  
@ConditionalOnMissingBean   容器中不存在指定Bean;  
@ConditionalOnExpression   满足SpEL表达式指定  
@ConditionalOnClass   系统中有指定的类  
@ConditionalOnMissingClass   系统中没有指定的类  
@ConditionalOnSingleCandidate   容器中只有一个指定的Bean,或者这个Bean是首选Bean  
@ConditionalOnProperty   系统中指定的属性是否有指定的值  
@ConditionalOnResource   类路径下是否存在指定资源文件  
@ConditionalOnWebApplication   当前是web环境  
@ConditionalOnNotWebApplication   当前不是web环境  
@ConditionalOnJndi   JNDI存在指定项  

我们如何知道哪些自动配置类生效

通过启用debug=true属性,来让控制台打印自动配置报告

============================ CONDITIONS EVALUATION REPORT ============================ Positive matches: (自动配置类启用的) ----------------- AopAutoConfiguration matched: - @ConditionalOnProperty (spring.aop.auto=true) matched (OnPropertyCondition) AopAutoConfiguration.ClassProxyingConfiguration matched: - @ConditionalOnMissingClass did not find unwanted class 'org.aspectj.weaver.Advice' (OnClassCondition) - @ConditionalOnProperty (spring.aop.proxy-target-class=true) matched (OnPropertyCondition) Negative matches: (自动配置类没有启用的) ----------------- ActiveMQAutoConfiguration: Did not match: - @ConditionalOnClass did not find required class 'javax.jms.ConnectionFactory' (OnClassCondition) AopAutoConfiguration.AspectJAutoProxyingConfiguration: Did not match: - @ConditionalOnClass did not find required class 'org.aspectj.weaver.Advice' (OnClassCondition)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zyypjj.html