1

I have some scheduled jobs in my project with @Schedule annotation, but don't want to inject all of them. Do you know how to skip injection of some jobs, or how can I do it in another way?

bralek
  • 23
  • 6

1 Answers1

0

You could configure the scheduled tasks in a property file. That way, you could add a boolean flag that you inject into any class containing the scheduled task. Then you could check inside your code if the task is enabled and should be executed.

There is detailed code over in question How to conditionally enable or disable scheduled jobs in Spring?.

If you want to decide if a @Scheduled task should be detected and registered at a ScheduledAnnotationBeanPostProcessor, you might want to look into the SchedulingConfigurer:

[It allows] registering scheduled tasks in a programmatic fashion as opposed to the declarative approach of using the @Scheduled annotation

Community
  • 1
  • 1
Wolfram
  • 8,044
  • 3
  • 45
  • 66