@scheduled 为 cron 表达式抛出异常
@scheduled throwing exception for cron expression
团队,
我已将 cron 表达式放入属性文件中。然后我尝试从 java 文件中引用该 cron 表达式,如图所示。
@Scheduled(cron= "${cron.expression}" )
public void test(){
...
}
它给我带来了以下错误:
Cron expression must consist of 6 fields (found 1 in "${cron.expression}"
我是这个调度程序的新手。请就如何使此表达式可配置提出建议。
谢谢
我在 AppConfig java 文件中添加了以下内容。
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
没有 PropertySourcesPlaceholderConfigurer,我们只能使用 Autowired 环境变量访问属性文件。但是使用 PropertySourcesPlaceholderConfigurer,我们可以使用 ${..} 使用 属性 文件变量。
有了这个逻辑,我的代码开始像魅力一样工作。
感谢@S.B 和@RaphaelRoth 的回复。
团队,
我已将 cron 表达式放入属性文件中。然后我尝试从 java 文件中引用该 cron 表达式,如图所示。
@Scheduled(cron= "${cron.expression}" )
public void test(){
...
}
它给我带来了以下错误:
Cron expression must consist of 6 fields (found 1 in "${cron.expression}"
我是这个调度程序的新手。请就如何使此表达式可配置提出建议。
谢谢
我在 AppConfig java 文件中添加了以下内容。
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
没有 PropertySourcesPlaceholderConfigurer,我们只能使用 Autowired 环境变量访问属性文件。但是使用 PropertySourcesPlaceholderConfigurer,我们可以使用 ${..} 使用 属性 文件变量。
有了这个逻辑,我的代码开始像魅力一样工作。
感谢@S.B 和@RaphaelRoth 的回复。