Springboot @ConditionalOnProperty注解

最近看了一段代码其中用到了@ConditionalOnProperty注解,直接没有了解过这个注解,今天看到了顺便了解一下

springboot ConditionalOnProperty注解

具体代码如下

  1. @Configuration
  2. public class WebConfig {
  3.  
  4. @Bean
  5. @ConditionalOnProperty(prefix = "rest", name = "auth-open", havingValue = "true", matchIfMissing = true)
  6. public AuthFilter jwtAuthenticationTokenFilter() {
  7. return new AuthFilter();
  8. }
  9.  
  10. }

prefix application.properties配置的前缀
name 属性是从application.properties配置文件中读取属性值
havingValue 配置读取的属性值跟havingValue做比较,如果一样则返回true;否则返回false。
如果返回值为false,则该configuration不生效;为true则生效
matchIfMissing = true表示如果没有在application.properties设置该属性,则默认为条件符合

上面代码的意思是
是否启动jwt的的配置,如果application.properties配置中没有设置就启动jwt,如果设置了true就启动,如果false就关闭
application.properties 配置如下

  1. rest:
  2. auth-open: true #jwt鉴权机制是否开启(true或者false)

 

如无特别说明,本站文章皆为原创,若要转载,务必请注明以下原文信息:
转载保留版权:springboot ConditionalOnProperty注解
本文链接地址:https://www.phpsong.com/3782.html

转载于:https://www.cnblogs.com/xikui/p/11226400.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值