Reputation: 814
Don't know might be the issue here, just added a standard cron job to my application, it works if it's hardcoded!
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.")
Throws out the following error
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
Worth mentioning, running the application inside IntelliJ seems to work,
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 * * * * *.
Upvotes: 3
Views: 7410
Reputation: 1
First try without "\" in @Scheduled like this:
@Scheduled(cron = "${qronicle.data-retention.retryCronSchedule}")
If this does not work, try add annotation to your class @EnableScheduling.
Upvotes: 0
Reputation: 641
Passing dynamic values to the annotations is not possible in java. You can check this post for your reference.
Passing dynamic parameters to an annotation?
Upvotes: 1