What is purpose of @ConditionalOnProperty annotation?
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?的更多相关文章
- Creating your own auto-configuration
44. Creating your own auto-configuration If you work in a company that develops shared libraries, or ...
- Spring Boot Reference Guide
Spring Boot Reference Guide Authors Phillip Webb, Dave Syer, Josh Long, Stéphane Nicoll, Rob Winch, ...
- SpringBoot - Starter
If you work in a company that develops shared libraries, or if you work on an open-source or commerc ...
- Jersey MVC
Jersey是JAX-RS(JavaAPI for RESTful Service)标准的一个实现,用于开发RESTful Web Application.可以参考JAX-RS的介绍(http://w ...
- interface类型
接口可使用的修饰符如下: InterfaceModifier: one of Annotation public protected private abstract static strictfp ...
- Spring Boot文档
本文来自于springboot官方文档 地址:https://docs.spring.io/spring-boot/docs/current/reference/html/ Spring Boot参考 ...
- 基于WebDriver&TestNG 实现自己的Annotation @TakeScreenshotOnFailure
相信用过Selenium WebDriver 的朋友都应该知道如何使用WebDriver API实现Take Screenshot的功能. 在这篇文章里,我主要来介绍对failed tests实现 t ...
- Spring Annotation Processing: How It Works--转
找的好辛苦呀 原文地址:https://dzone.com/articles/spring-annotation-processing-how-it-works If you see an annot ...
- Spring ConditionalOnProperty
Spring Annotation @ConditionalOnProperty spring doc解释 @Conditional: Indicates that a component is on ...
随机推荐
- Linux 网络设备驱动开发(一) —— linux内核网络分层结构
Preface Linux内核对网络驱动程序使用统一的接口,并且对于网络设备采用面向对象的思想设计. Linux内核采用分层结构处理网络数据包.分层结构与网络协议的结构匹配,既能简化数据包处理流程,又 ...
- jquery选择div下的ul下的li下的a
使用jQuery选择器: $("div#div的id ul li a")//选择的是div下 ul下所有li下的所有a标签 $("div#div的id").ch ...
- Android两次后退键退出
转载请注明出处:http://blog.csdn.net/javacattle/article/details/41964045 仅仅要在 *.Java 文件里加入就可以 private int ba ...
- Ubuntu 中/etc/resolv.conf 文件修改丢失的解决方案
方法一 1.需要创建一个文件/etc/resolvconf/resolv.conf.d/tail sudo vi /etc/resolvconf/resolv.conf.d/tail 2.在该文件中写 ...
- 给你的webstorm添加快速生成注释得快捷键
打开File----setting-map-搜搜"fix doc"
- x为正变数,求y=x^3/(x^4+4)的最大值
设z=1/y=x4+4/x3 显然,当z有最小值时,y有最大值,求得zmin,就得到了ymax 而z=x+4/x3=x/3+x/3+x/3+4/x3 根据正实数算术平均数大于等于它们的几何平均数的定理 ...
- discuz,ecshop的伪静态规则(apache+nginx)
discuz(nginx): (备注:该规则也适用于二级目录) rewrite ^([^\.]*)/topic-(.+)\.html$ $/portal.php?mod=topic&topic ...
- Discuz常见小问题-如何设置QQ邮箱注册验证
开启POP3/SMTP服务器,需要发送短信,然后点击我已发送,得到一个指定的密码 开启之后得到的授权码 开启IMAP/SMTP还需要发送一次短信,得到一个另外的授权码 然后在后台设置为下面 ...
- 轻量级UIImageView分类缓存 库 AsyncImageView 使用
轻量级UIImageView分类缓存 库 AsyncImageView 使用 一: AsyncImageView 主页:https://github.com/nicklockwood/AsyncIma ...
- Unity时钟定时器插件——Vision Timer源码分析之二
Unity时钟定时器插件——Vision Timer源码分析之二 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处:http.dsqiu.iteye.com 前面的已经介绍了vp_T ...