By looking at some examples of running quartz jobs in a spring boot app, I see many of them are actually declaring the Job with the @Component annotation :
It seems to be completly useless as the job factory will create a new instance every time the job is triggered.
I can see in my app that the method SpringBeanJobFactory.createJobInstance is called each time the job is executed. I removed the @Component annotation and it works perfectly, so is there any advantage of declaring a Job as a spring bean ?
In some cases you need to inject spring managed components into your job, for example some service or repository (to get some data to process by job). In such case, you wanna create a job as a component and allows spring to inject required beans into it. In such case your job's superclass can extend QuartzJobBean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With