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.

最新文章

  1. [Maven]初次实践
  2. AC自动机 LA 4670 Dominating Patterns
  3. Poj(2679),SPFA,二级比较
  4. 浅谈线程池(上):线程池的作用及CLR线程池
  5. 关于linux python vim的一些基础知识(很零散)
  6. 【转】阿里2015校招面试回忆(成功拿到offer)
  7. 理解C#系列 / 核心C# / 常量
  8. JDBC增删改查
  9. java 下拉框级联及相关(转)
  10. android 快速创建一个新的线程
  11. Cocos2d-x3.0 DrawNode吸取
  12. OpenCV ——双线性插值(Bilinear interpolation)
  13. 转:Loadrunner——Simulate a new user on each iteration设置
  14. SSD写入放大问题[转]
  15. 前端到docker入门
  16. 聚类——GMM
  17. 设计模式之Jdk动态代理
  18. Ubuntu学习总结-01 安装Ubuntu
  19. 大数据系列之数据仓库Hive命令使用及JDBC连接
  20. 第三百五十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行、scrapy-splash、splinter

热门文章

  1. 给 Easyui Datagrid 扩展方法
  2. DHCP安装配置详解
  3. 使用BeyondCompare比较文件夹下的文件时,相同的文件内容,但显示为不相同
  4. win10 mysql57密码重置
  5. (剑指Offer)面试题54:表示数值的字符串
  6. android-关于友盟的自动版本更新(面向小白)
  7. VC中关于预编译头文件的概括,以及无法打开预编译头文件的错误解决
  8. 高阶函数简述 js
  9. Java之JVM调优案例分析与实战(3) - 堆外内存导致的溢出错误
  10. excel 快速比对两列数据差异