遇到无效的@Scheduled方法'run':确实是'cron','fixedDelay(String)'或'fixedRate(String)'属性之一

时间:2019-06-18 16:44:01

标签: java spring annotations spring-scheduled

不知道这可能是问题所在,只是在我的应用程序中添加了标准的cron作业,如果它是硬编码的,它就可以工作!

application.properties

qronicle.data-retention.retryCronSchedule = 0 * * * * *

DataRetentionDeliveryMethod

@Scheduled(cron = "\${qronicle.data-retention.retryCronSchedule}")
@Transactional
override fun run() {
    LOGGER.info("Running retry job.")

    val retentionRecords = retentionRepository.findAllByStateAndRetryCountLessThan()
    LOGGER.info("Will attempt to reprocess ${retentionRecords.size} retention records.")

抛出以下错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-18 14:02:25.221 ERROR 20 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'retentionRetryJob$qronicle' defined in class path resource [com/netapp/qronicle/config/ApplicationConfig.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': Exactly one of the 'cron', 'fixedDelay(String)', or 'fixedRate(String)' attributes is required

值得一提的是,在IntelliJ中运行应用程序似乎可以正常工作

giving the following log line...
2019-06-18 17:30:35.388  INFO 15642 --- [           main] c.n.q.p.delivery.RetentionRetryJob       : Started retention retry job with schedule: 0 * * * * *.

1 个答案:

答案 0 :(得分:1)

在Java中无法将动态值传递给注释。您可以查看此帖子以供参考。

Passing dynamic parameters to an annotation?