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

具体代码如下

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

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

Springboot @ConditionalOnProperty注解的更多相关文章

  1. SpringBoot 常用注解(持续更新)

    SpringBoot 常用注解 @SpringBootApplication @Bean @ComponentScan @ControllerAdvice @ExceptionHandler @Res ...

  2. 常见的springmvc、SpringBoot的注解

    springMvc的常用注解 : @Controller :用于标记在一个类上,使用它标记的类就是一个springmcv Controller对象,分发处理器将会扫描使用了该注解 的类的方法,并检测该 ...

  3. 浅谈SpringBoot核心注解原理

    SpringBoot核心注解原理 今天跟大家来探讨下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot为什么不需要XML,达到零配置 ...

  4. SpringBoot的注解注入功能移植到.Net平台(开源)

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...

  5. SpringBoot(14)—注解装配Bean

    SpringBoot(14)-注解装配Bean SpringBoot装配Bean方式主要有两种 通过Java配置文件@Bean的方式定义Bean. 通过注解扫描的方式@Component/@Compo ...

  6. SpringBoot 入门篇(二) SpringBoot常用注解以及自动配置

    一.SpringBoot常用注解二.SpringBoot自动配置机制SpringBoot版本:1.5.13.RELEASE 对应官方文档链接:https://docs.spring.io/spring ...

  7. [技术博客] SPRINGBOOT自定义注解

    SPRINGBOOT自定义注解 在springboot中,有各种各样的注解,这些注解能够简化我们的配置,提高开发效率.一般来说,springboot提供的注解已经佷丰富了,但如果我们想针对某个特定情景 ...

  8. Spring SpringMVC SpringBoot SpringCloud 注解整理大全

    Spring SpringMVC SpringBoot SpringCloud 注解整理 才开的博客所以放了一篇以前整理的文档,如果有需要添加修改的地方欢迎指正,我会修改的φ(๑˃∀˂๑)♪ Spri ...

  9. 【实战】Springboot +jjwt+注解实现需登录才能操作

    springboot +jjwt+注解实现需登录才能调用接口 1.开发需要登录才能进行操作的自定义注解NeedLogin,后面可以写在需要登陆后操作的接口上 package com.songzhen. ...

随机推荐

  1. PAT-1111 Online Map (30分) 最短路+dfs

    明天就要考PAT,为了应付期末已经好久没有刷题了啊啊啊啊,今天开了一道最短路,状态不是很好 1.没有读清题目要求,或者说没有读完题目,明天一定要注意 2.vis初始化的时候从1初始化到n,应该从0开始 ...

  2. 什么叫工业4.0,这篇接地气的文章终于讲懂了(ZT)

    原地址:https://www.cnblogs.com/namei/p/6110382.html 笔者早年从事过工业自动化行业,后来去了几个城市,讲过<工业互联网与工业文明史>这门课,以至 ...

  3. jQuery 基础知识

    一.序言 jQuery是一个快速.简洁的JavaScript框架,是继Prototype之后的又一个优秀的JavaScript代码库(JavaScript框架).jQuery设计的宗旨是"W ...

  4. 使用node建立本地服务器访问静态文件

    最终目录结构 demo │ node_modules └───public │ │ index.html │ │ index.css │ └───index.js └───server.js 一.使用 ...

  5. orangepi设置vnc开机自启动

    首先需要创建一个文件,执行以下命令,自动打开空白文件,在里面编辑内容即可 sudo gedit /etc/init.d/tightvncserver 把以下内容粘贴进去,然后点击保存即可. #!/bi ...

  6. coco creator编辑动画坑之拖图片

    如图所示,批量选中多张图片之后,拖到右下角的框中,发现有时候可以有时候不行.这个我觉得是个软件的bug 后来经过测试发现只有在粉红色圈的高度才可以正确放入图片,否则都放不了.

  7. array_map 去除数组参数里面左右两端空格

    <?php class Test{ public function trimArray($params){ if (!is_array($params)) return trim($params ...

  8. mysql8.0授权远程登录

    之前一直用mysql5.6 远程授权登录,后来换mysql8.0原来的授权方式报错 mysql> grant all privileges on *.* to 'root'@'%' identi ...

  9. Keras实现Hierarchical Attention Network时的一些坑

    Reshape 对于的张量x,x.shape=(a, b, c, d)的情况 若调用keras.layer.Reshape(target_shape=(-1, c, d)), 处理后的张量形状为(?, ...

  10. kali linux Desktop Environemt types and kali linux install virualbox

    1.we know the kali linux desktop environmet can also be costomized ,Desktop environmet can use GNOME ...