SpringBoot:@Conditional注解集合

ConditionalOnBean:当容器里有指定的bean的条件下
ConditionalOnClass:当类路径下有指定的类的条件下
ConditionalOnExpression: 基于SpEL表达式作为判断条件
ConditionalOnJava:基于java版本作为判断条件
ConditionalOnJndi:在JNDI存在的条件下查找指定的位置
ConditionalOnMissingBean :当容器里没有指定的bean的情况下
ConditionalOnMissingClass: 当容器没有指定的类的情况下
ConditionalOnNoWenApplication:当前项目不是web项目的条件下
ConditionalOnProperty:指定的属性是否有指定的值
ConditionalOnResource:类路径是否有指定的值
ConditionalOnSingleCandidate:当指定的bean在容器中只有一个,或者虽然有多个但是指定首选bean
ConditionalOnWebApplication:当前项目是web项目的条件下

自动配置类必须在一定条件下才会生效。都通过@Conditional注解标签来配置实现。

我们可以通过启用配置属性debug=true,来使项目启动时,自动在控制台输出自动匹配报告。

Positive matches:(启用的自动配置类)
-----------------

   CodecsAutoConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.http.codec.CodecConfigurer' (OnClassCondition)

   CodecsAutoConfiguration.JacksonCodecConfiguration matched:
      - @ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)

   CodecsAutoConfiguration.JacksonCodecConfiguration#jacksonCodecCustomizer matched:
      - @ConditionalOnBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) found bean 'jacksonObjectMapper' (OnBeanCondition)

   DispatcherServletAutoConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
      - found 'session' scope (OnWebApplicationCondition)
.....


Negative matches:(没有启用的自动配置类)
-----------------

   ActiveMQAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'javax.jms.ConnectionFactory' (OnClassCondition)

   AopAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'org.aspectj.lang.annotation.Aspect' (OnClassCondition)

   ArtemisAutoConfiguration:
      Did not match:
         - @ConditionalOnClass did not find required class 'javax.jms.ConnectionFactory' (OnClassCondition)
..........

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值