Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 遇到无效的@Scheduled方法';运行';:正好是';cron'';固定延迟(字符串)和#x27;,或';固定利率(字符串)和#x27;属性是必需的_Java_Spring_Annotations_Spring Scheduled - Fatal编程技术网

Java 遇到无效的@Scheduled方法';运行';:正好是';cron'';固定延迟(字符串)和#x27;,或';固定利率(字符串)和#x27;属性是必需的

Java 遇到无效的@Scheduled方法';运行';:正好是';cron'';固定延迟(字符串)和#x27;,或';固定利率(字符串)和#x27;属性是必需的,java,spring,annotations,spring-scheduled,Java,Spring,Annotations,Spring Scheduled,不知道这里可能有什么问题,只是在我的应用程序中添加了一个标准的cron作业,如果它是硬编码的,它就可以工作 应用程序属性 qronicle.data-retention.retryCronSchedule = 0 * * * * * DataRetentionDeliveryMethod @Scheduled(cron = "\${qronicle.data-retention.retryCronSchedule}") @Transactional override fun run() {

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

应用程序属性

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 * * * * *.

在java中,向注释传递动态值是不可能的。你可以查看这篇文章作为参考