Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MethodValidationPostProcessor conflict with Scheduler #24165

Closed
Zheaoli opened this issue Dec 9, 2019 · 2 comments
Closed

MethodValidationPostProcessor conflict with Scheduler #24165

Zheaoli opened this issue Dec 9, 2019 · 2 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@Zheaoli
Copy link

Zheaoli commented Dec 9, 2019

I use the Spring Boot v2.0.5.RELEASE which depends on Spring 5.0.9 Release

I got a problem when I need both MethodValidationPostProcessor and Scheduled

here's the detail.

When I just use Scheduled like below

@SpringBootApplication
@EnableConfigServer
@EnableScheduling
public class SpringConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringConfigServerApplication.class, args);
    }

    @Scheduled(fixedDelay = 5000)
    public void test() {
        System.out.println("Demo");
    }
}

the scheduler works well as what I want. But when I add a MethodValidationPostProcessor like below

@SpringBootApplication
@EnableConfigServer
@EnableScheduling
public class SpringConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringConfigServerApplication.class, args);
    }

    @Bean
    public MethodValidationPostProcessor methodValidationPostProcessor() {
        MethodValidationPostProcessor methodValidationPostProcessor = new MethodValidationPostProcessor();
        methodValidationPostProcessor.setProxyTargetClass(true);
        return methodValidationPostProcessor;
    }

    @Scheduled(fixedDelay = 5000)
    public void test() {
        System.out.println("Demo");
    }
}

the scheduler doesn't work. I have already checked the org.springframework.scheduling.config.ScheduledTaskRegistrar, the scheduler inits as well, but there isn't any task in all of the task variables such as fixedRateTasks, fixedDelayTasks and etc.

Is there any chance that we can use MethodValidationPostProcessor and the scheduler together?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 9, 2019
@snicoll
Copy link
Member

snicoll commented Dec 9, 2019

@Zheaoli the post-processor method should be static to prevent early initialization of the whole chain. You also should have a message in the log stating that some beans couldn't be post-processed. This is the reason why scheduling doesn't work with such arrangement. If moving it to static doesn't fix the problem, please share a small sample (zip or github repo) we can run ourselves and we can reconsider.

@snicoll snicoll closed this as completed Dec 9, 2019
@snicoll snicoll added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 9, 2019
@Zheaoli
Copy link
Author

Zheaoli commented Dec 9, 2019

Your suggestion is working! thanks! BTW, is there any chance to add a tips in documentation? I think this chain make many people confuse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants