当前位置:网站首页>@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 .
边栏推荐
- Flinksql synchronizes data from Oracle to Doris, with a total of more than 50 fields and more than 30 million entries in Oracle tables
- Poj2446 chessboard [maximum matching of bipartite graph]
- PG synchronizes multiple data tables to MySQL. Is there a way to simplify the configuration?
- 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
- JS single thread understanding notes - Original
- Mongodb slow query and index
- Top 10 international NFT exchanges
- flinksql从Oracle同步数据到Doris,一共50几个字段,Oracle表中3000多万条
- Firefox 103 发布,更快、更安全
- 【表达式计算】双栈 : 表达式计算问题的通用解法
猜你喜欢

V. introduction of other objectives and general options

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

Overview of famous inner classes and anonymous inner classes

Zhongke Lanxun fell 30% on the first day of listing: Huang Zhiqiang, 60, started a company with a market value of 7.7 billion

Aike AI frontier promotion (7.27)

Map interface

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

Is it easy to find a job after programmer training and learning

GAN:生成对抗网络 Generative Adversarial Networks

Dominoes staged: the beginning and end of the three arrow capital crash
随机推荐
Article reproduction: srcnn
Why does the class annotated with @configuration generate cglib proxy?
Detail the execution process of JDBC query method
爬虫
Regular expressions remove spaces at both ends
字节跳动的 Flink OLAP 作业调度和查询执行优化实践
Background and framework introduction and basic environment preparation of hucang integrated e-commerce project
V. introduction of other objectives and general options
正则表达式去除两端空格
Distributed system architecture theory and components
SparkSubmit.main()方法提交外部参数,远程提交standalone集群任务
592. Fraction addition and subtraction: introduction to expression calculation
Xposed+fdex2 app shelling (black cat complains about app shelling)
Laboratory procedures and references of chloramphenicol acetate
Seata 在蚂蚁国际银行业务的落地实践
String to realize fuzzy query
Security measures for tcp/ip protocol vulnerabilities
Uniapp video video playback is not completed. It is forbidden to drag the progress bar fast forward
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
Poj2594 treasure exploration [bipartite graph minimum path coverage] [Floyd]