Skip to content

Problem with @Schedule with Quartz features in CronExpression  #26289

@alvaro-nogueira

Description

@alvaro-nogueira

I am running with Spring Boot v2.4.1 and Spring v5.3.2

With I try to run with @Scheduled(cron = "0 0 10 ? * TUE#1") works fine, as discussed in #22436.
But when I try to run with @Scheduled(cron = "0 0 10 ? * TUE#1,TUE#3,TUE#5") it gives the error below.

My code example is as follows:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@SpringBootApplication
@EnableScheduling
public class TestScheduledApplication{
    public static void main(String[] args) {
        SpringApplication.run(TestScheduledApplication.class, args);
    }
    @Scheduled(cron = "0 0 10 ? * TUE#1,TUE#3,TUE#5")
    public void testScheduled(){
        System.out.println("hello world");
    }
}

Error:

Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'testScheduled': For input string: "2#1,2#3,2" in cron expression "0 0 10 ? * TUE#1,TUE#3,TUE#5"
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:511)
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$null$1(ScheduledAnnotationBeanPostProcessor.java:374)
	at java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$2(ScheduledAnnotationBeanPostProcessor.java:374)
	at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
	at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:373)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:444)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609)

Is this a real issue or is not suported at all?

PS: As workaround I'm creating 3 separated schedules:
@Scheduled(cron = "0 0 10 ? * TUE#1"), @Scheduled(cron = "0 0 10 ? * TUE#3"), @Scheduled(cron = "0 0 10 ? * TUE#5")

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions