lta*_*rne 11 cron spring schedule spring-boot
有没有办法在Spring的@Scheduled
cron
配置中从propertyClass调用getter(甚至变量)?以下内容无法编译:
@Scheduled(cron = propertyClass.getCronProperty())
要么 @Scheduled(cron = variable)
我想避免直接抓住房产:
@Scheduled(cron = "${cron.scheduling}")
Run Code Online (Sandbox Code Playgroud)
简短的回答 - 它不可能开箱即用.
在@Scheduled
注释中作为"cron表达式"传递的值将ScheduledAnnotationBeanPostProcessor
使用StringValueResolver
接口实例在类中处理.
StringValueResolver
有3个开箱即用的实现 - 对于Placeholder
(例如$ {}),对于Embedded
值和Static
字符串 - 没有一个可以实现你正在寻找的东西.
如果必须在注释中使用属性占位符而不惜一切代价避免,请删除注释并以编程方式构造所有内容.您可以使用注册任务ScheduledTaskRegistrar
,这是@Scheduled
注释实际执行的操作.
我建议使用任何最简单的解决方案,并通过测试.
归档时间: |
|
查看次数: |
9925 次 |
最近记录: |