Spring @Scheduled 默认值

Rac*_*naj 2 java spring properties

我正在使用 PropertyPlaceholderConfigurer 来获取 Spring 计划注释配置中的 java 属性

@Scheduled(cron = "${execution.frequency}")
public void generateReport() {
Run Code Online (Sandbox Code Playgroud)

当没有定义覆盖属性值时,有没有办法指定默认值?

Spring 3支持 ${my.property:defaultValue} 语法,但在注释上不允许,我尝试传递变量但也不允许,注释属性 Scheduled.cron 的值必须是常量表达式

小智 5

这个语法对我有用

@Scheduled(cron = "${execution.frequency:0 */30 * * * ?}")
public void generateReport() {
Run Code Online (Sandbox Code Playgroud)

您所需要的只是根据您的需要修复默认的 cron 表达式