java.lang.IllegalStateException:遇到无效的@Scheduled方法“ execute”:对于输入字符串:“ 1#1”

时间:2018-08-02 16:47:45

标签: java spring spring-boot cron scheduled-tasks

我有以下方法声明:

@Scheduled(cron = "0 0 12 ? * MON#1")
protected synchronized void execute() {...}

但是我的应用程序启动失败,并且我在日志中看到以下错误:

Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'execute': For input string: "1#1"
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:461) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:331) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    ... 19 common frames omitted

如何更正?

1 个答案:

答案 0 :(得分:1)

当Spring Boot无法识别cron表达式时,将发生错误。应该可能是由于MON#1部分。

This可能有助于在Spring启动中找到正确的cron表达式。