当前位置:网站首页>@Simple understanding and use of conditionalonproperty
@Simple understanding and use of conditionalonproperty
2022-07-27 13:13:00 【bulingbuling^_^】
@ConditionalOnProperty Annotation controls whether the component is injected spring Annotations
@Configuration
@Slf4j
@EnableScheduling
//@Conditional(CheckEnvironmentCondition.class)
@ConditionalOnProperty(prefix = "demo", name = "conditional", havingValue = "true", matchIfMissing = true)
public class ConditionalConfigTest {
@Scheduled(cron = "*/5 * * * * ?")
private void updateJob(){
System.out.println("ConditionalOnProperty---Test:"+ LocalDateTime.now());
}
}Configuration parameters match , Successful injection

Function of each attribute Source code
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@Documented
@Conditional(OnPropertyCondition.class)
public @interface ConditionalOnProperty {
/**
* Alias for {@link #name()}.
* @return the names
*/
String[] value() default {};
/**
* A prefix that should be applied to each property. The prefix automatically ends
* with a dot if not specified. A valid prefix is defined by one or more words
* separated with dots (e.g. {@code "acme.system.feature"}).
* @return the prefix
*/
String prefix() default "";
/**
* The name of the properties to test. If a prefix has been defined, it is applied to
* compute the full key of each property. For instance if the prefix is
* {@code app.config} and one value is {@code my-value}, the full key would be
* {@code app.config.my-value}
* <p>
* Use the dashed notation to specify each property, that is all lower case with a "-"
* to separate words (e.g. {@code my-long-property}).
* @return the names
*/
String[] name() default {};
/**
* The string representation of the expected value for the properties. If not
* specified, the property must <strong>not</strong> be equal to {@code false}.
* @return the expected value
*/
String havingValue() default "";
/**
* Specify if the condition should match if the property is not set. Defaults to
* {@code false}.
* @return if the condition should match if the property is missing
*/
boolean matchIfMissing() default false;
}havingValue: Whether the defined values are equal , Decide whether to inject .
matchIfMissing: If this property is not set , If you need havingValue To match .
After Baidu , For these two combinations , The explanation is very convoluted , In a nutshell :
matchIfMissing by true The comparison object is null when , It will inject .
When used together , With havingValue Subject to .
边栏推荐
- 改变线程状态的方法
- nodejs body-parser中间件处理类型 multipart/form-data 的 POST 表单数据,req.body无法接收到数据
- Security measures for tcp/ip protocol vulnerabilities
- JS date and time format (year, month, day, hour, minute, second, week, quarter, time difference acquisition, date and timestamp conversion function)
- [cute new solution] Fibonacci sequence
- Overview of static inner classes and non static inner classes
- Reptile
- SSM practical project - front back separation (easy to understand)
- Gartner 权威预测未来4年网络安全的8大发展趋势
- 完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
猜你喜欢

Minimally invasive brain science broke the listing: the company's market value is HK $14.3 billion, and minimally invasive medical is the major shareholder

SparkSubmit.main()方法提交外部参数,远程提交standalone集群任务

"Game engine light in light out" 4.1 unity shader and OpenGL shader

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

隔离级别

Self built personalized automatic quotation system to cope with changeable quotation mode

【萌新解题】斐波那契数列

爱可可AI前沿推介(7.27)

Dominoes staged: the beginning and end of the three arrow capital crash

Getting started for beginners: build your own blog with WordPress
随机推荐
Vi. analysis of makefile.build
V. introduction of other objectives and general options
延迟队列DelayQueue性能测试
What should I do if I can't see any tiles on SAP Fiori launchpad?
概述静态内部类与非静态内部类
【表达式计算】双栈 : 表达式计算问题的通用解法
MySQL扩展
js日期时间格式化(年月日、时分秒、星期、季度、获取时间差、日期与时间戳转换的功能)
II. Analysis of the execution process of make menuconfig
Summary of common methods of ArrayList
Mongodb slow query and index
BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (
POJ1273 Drainage Ditches【最大流】【SAP】
What are metauniverse and NFT digital collections?
Flinksql synchronizes data from Oracle to Doris, with a total of more than 50 fields and more than 30 million entries in Oracle tables
C program debugging and exception handling (try catch)
Is it easy to find a job after programmer training and learning
Dominoes staged: the beginning and end of the three arrow capital crash
Top 10 international NFT exchanges
概述有名内部类与匿名内部类