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?
Asked
Active
Viewed 1,863 times
1 Answers
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
-
Yes, but I don't want to instatiate/inject that bean at all. – bralek Jan 21 '15 at 15:19
-
Ok, see my edit, you might want to use the manual configuration of scheduled tasks to have more control. – Wolfram Jan 21 '15 at 15:26