http://stackoverflow.com/questions/26394778/what-is-purpose-of-conditionalonproperty-annotation

****************************************************

I just modified spring boot configuration, and encountered

@ConditionalOnProperty(prefix = "spring.social.", value = "auto-connection-views") from org.springframework.boot.autoconfigure.social.TwitterAutoConfiguration.java 

        @Bean(name = { "connect/twitterConnect", "connect/twitterConnected" })
@ConditionalOnProperty(prefix = "spring.social.", value = "auto-connection-views")
public View twitterConnectView() {
return new GenericConnectionStatusView("twitter", "Twitter");
}

answers

The annotation is used to conditionally create a Spring bean depending on the configuration of a property. In the usage you've shown in the question the bean will only be created if the spring.social.auto-connection-views property exists and it has a value other than false. This means that, for this View bean to be created, you need to set the spring.social.auto-connection-views property and it has to have a value other than false.

如果property spring.social.auto-connection-views存在,并且值不为false,创建bean.

You can find numerous other uses of this annotation throughout the Spring Boot code base. Another example is:

@ConditionalOnProperty(prefix = "spring.rabbitmq", name = "dynamic", matchIfMissing = true)
public AmqpAdmin amqpAdmin(CachingConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
}

Note the use of matchIfMissing. In this case the AmqpAdmin bean will be created if the spring.rabbitmq.dynamic property exists and has a value other than false or the property doesn't exist at all. This makes the creation of the bean opt-out rather than the example in the question which is opt-in.

如果property spring.rabbitmq.dynamic存在,并且值不为false,创建bean

matchIfMissing = true, 如果改属性条目不存在,创建bean.

What is purpose of @ConditionalOnProperty annotation?的更多相关文章

  1. Creating your own auto-configuration

    44. Creating your own auto-configuration If you work in a company that develops shared libraries, or ...

  2. Spring Boot Reference Guide

    Spring Boot Reference Guide Authors Phillip Webb, Dave Syer, Josh Long, Stéphane Nicoll, Rob Winch,  ...

  3. SpringBoot - Starter

    If you work in a company that develops shared libraries, or if you work on an open-source or commerc ...

  4. Jersey MVC

    Jersey是JAX-RS(JavaAPI for RESTful Service)标准的一个实现,用于开发RESTful Web Application.可以参考JAX-RS的介绍(http://w ...

  5. interface类型

    接口可使用的修饰符如下: InterfaceModifier: one of Annotation public protected private abstract static strictfp  ...

  6. Spring Boot文档

    本文来自于springboot官方文档 地址:https://docs.spring.io/spring-boot/docs/current/reference/html/ Spring Boot参考 ...

  7. 基于WebDriver&TestNG 实现自己的Annotation @TakeScreenshotOnFailure

    相信用过Selenium WebDriver 的朋友都应该知道如何使用WebDriver API实现Take Screenshot的功能. 在这篇文章里,我主要来介绍对failed tests实现 t ...

  8. Spring Annotation Processing: How It Works--转

    找的好辛苦呀 原文地址:https://dzone.com/articles/spring-annotation-processing-how-it-works If you see an annot ...

  9. Spring ConditionalOnProperty

    Spring Annotation @ConditionalOnProperty spring doc解释 @Conditional: Indicates that a component is on ...

随机推荐

  1. (Inside Out) Web地图坐标系——TDT的奇妙

    一个GIS科班出生的研究生.把已还到课本的基础GIS知识,准备又一次学习,并结合这几年下来自身在行业中GIS的应用.总结一些有用的GIS知识点.一备不时之需,二为积累沉淀,三则是年龄越大.记性越差,加 ...

  2. PHP实现双向链表

    看了很久数据结构但是没有怎么用过,在网上看到了关于PHP的数据结构,学习了一下,与大家一起分享一下.上一次分享了链表,这次来补充说一下双向链表. 简短不割                        ...

  3. 开源力量:微软竟开源 PowerShell

    导读 曾经有段时间,微软称 Linux 是“癌症”,但是随着时光流逝,现在微软已经认识到了开源世界的不断增长,除了在这个领域加大投入之外别无选择.微软已经启动了几个开源项目,希望能吸引一些 Linux ...

  4. 利用VS2010开发一个跳转页面aspx

    在开发项目的过程中,由于要集成Cognos的报表通过URL,但是Cognos报表的本身URL长度过程,那么此时就需要开发一个跳转的页面,下面我们就采用VS2010开发一个跳转的页面Default.as ...

  5. [Firebase] 4. Firebase Object related Database

    The idea: This post we are going to learn how to build a Firebase Forage with object related databas ...

  6. matlab中的size(),length(),ndims()函数的使用方法

    1.size()使用方法: size(a)表示矩阵每一个维度的长度 比方size([1 2 3;4 5 6]) 等于[2 3]: 表示他有2行3列. size([1 2 3]) 等于[1 3]: 表示 ...

  7. Python中的作用域

    Python中的作用域 Python 中,一个变量的作用域总是由在代码中被赋值的地方所决定的. 当 Python 遇到一个变量的话他会按照这样的顺序进行搜索: 本地作用域(Local)→当前作用域被嵌 ...

  8. 【树莓派】树莓派raspi-config配置

    发现有些树莓派盒子,输入的结果和键盘的实际字符有差异,比如输入 | ,结果显示为 ~. 这是因为树莓派的键盘设置问题. 可以通过设置raspi-config进行配置: 第一次使用树莓派的时候需要进行一 ...

  9. Python 对字符串切片

    对字符串切片字符串 'xxx'和 Unicode字符串 u'xxx'也可以看成是一种list,每个元素就是一个字符.因此,字符串也可以用切片操作,只是操作结果仍是字符串:>>> 'A ...

  10. 金蝶K3,域环境中,无本地用户管理员权限的域用户如何设置注册表权限?

    如果该用户是属于Power Users组:只需要给用户添加注册表中的HKEY_LOCAL_MACHINE的SOFTWARE完全控制的权限.(勾选允许父项的继承权限和传播到该对象和所有子对象) 如果该用 ...