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 ...
随机推荐
- csm pssm +pcf pcss sdsm
这几个shadow算法 pcf是sample时候用的 按照一个mode采样几个位置 根据采样结果 决定0-1 可以是0.234 这样就不是 0或者1 就是soft了 主要讲下pcss 是啥 因为我之 ...
- 已阻止安装程序vs2015
Burn v3.7.4906.0, Windows v10.0 (Build 15063: Service Pack 0), path: H:\vs_enterprise.exe, cmdline: ...
- zend studio 13.0.0 安装破解汉化
zend studio 13安装破解汉化步骤 官网原版下载 http://downloads.zend.com/studio-eclipse/13.0.0/ZendStudio-13.0.0-win3 ...
- (剑指Offer)面试题39:二叉树的深度
题目: 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. 结点的定义如下: struct TreeNode{ int val; ...
- authpuppy 认证服务器搭建
此文仅限于搭建authpuppy认证服务器,不包含认证插件等安装,仅说明步骤以备下次安装忘记步骤.耽误时间. 环境:ubuntu10.04 软件版本:authpuppy-1.0.0-stable.tg ...
- MFC获得主窗体和父窗体指针
MFC编程中经常遇到子窗体向父窗体传递參数的情况,这就须要获得父窗体的指针. 例:主对话框CMyMainDlg通过buttonButtonA进入对话框CMyParentDlg.CMyParentDlg ...
- .NET反编译之manager,base.AutoScaleMode修复
使用反编译软件导出项目时,出现警告:设计器无法处理第X 行的代码:this.AutoScaleMode = AutoScaleMode.Font;方法"InitializeComponent ...
- 算法笔记_037:寻找和为定值的两个数(Java)
目录 1 问题描述 2 解决方案 2.1 排序夹逼法 1 问题描述 输入一个整数数组和一个整数,在数组中查找两个数,满足他们的和正好是输入的那个整数.如果有多对数的和等于输入的整数,输出任意一对即 ...
- 【Django】TemplateDoesNotExist at /login/
在Django项目中配置一个简单的页面跳转 说明 OliverPro 为项目名称 ProApp 为应用程序 项目文件结构如下: 文件配置如下: 项目中的urls 应用程序urls views.py文件 ...
- springmvc处理流程
SpringMVC核心处理流程: 1.DispatcherServlet前端控制器接收发过来的请求,交给HandlerMapping处理器映射器 2.HandlerMapping处理器映射器,根据请求 ...