使用@Scheduled annotation的Spring cron不会从属性文件中提取表达式

使用@Scheduled annotation的Spring cron不会从属性文件中提取表达式,spring,spring-boot,cron,spring-scheduled,Spring,Spring Boot,Cron,Spring Scheduled,我正在尝试从@Scheduled annotation的属性文件中读取cron表达式 但是,当我启动服务器时,会出现如下错误 Encountered invalid @Scheduled method 'scheduleServicePrincipalOrchestorJob': For input string: "'0 不知道这里发生了什么 我的注释看起来像- @Scheduled(cron= "${abc.cronExpression}", zone="America/Los_Angel

我正在尝试从
@Scheduled annotation
的属性文件中读取cron表达式

但是,当我启动服务器时,会出现如下错误

Encountered invalid @Scheduled method 'scheduleServicePrincipalOrchestorJob': For input string: "'0
不知道这里发生了什么

我的注释看起来像-

@Scheduled(cron= "${abc.cronExpression}", zone="America/Los_Angeles")
我的application.properties看起来像

abc.cronExpression="0 8 0 0 0 0"

有什么问题吗?

删除cron表达式中的引号。此外,某些字段不能为0,因此请从以下有效表达式开始,并根据需要进行调整:

abc.cronExpression=0 0/5***


也就是说,在第二个0,每5分钟,每天。

在Spring中使用
@Scheduled
的cron表达式由以下部分组成:

<second> <minute> <hour> <day-of-month> <month> <day-of-week> <year>
其中,
*
指任何月份内的任何一天

或者,您可以使用以下命令仅在第一个月的第一天执行代码:

bc.cronExpression=0 8 0 1 1 0

有关更多信息,Bealdung将一个to cron表达式放在一起,这可能有助于您进一步理解它。

也许您可以参考这个

注释属性Scheduled.cron的值必须是常量表达式

删除属性文件中的
bc.cronExpression=0 8 0 1 1 0