How to use @Autowired in a Quartz Job?

In your solution you are using the spring @Autowired annotation in a class that is not instantiated by Spring. Your solution will still work if you remove the @Autowired annotation because Quartz is setting the property, not Spring.

Quartz will try to set every key within the JobDataMap as a property. E.g. since you have a key “myDao” Quartz will look for a method called “setMyDao” and pass the key’s value into that method.

If you want Spring to inject spring beans into your jobs, create a SpringBeanJobFactory and set this into your SchedulerFactoryBean with the jobFactory property within your spring context.

SpringBeanJobFactory javadoc:

Applies scheduler context, job data map and trigger data map entries
as bean property values

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)