2

I have to use Spring Quartz with JDBC Store for scheduling the app. I am not sure how to handle the Dependency Injection when the jobs are triggered from the database. One way would be retrieve the beans from the context after the job is triggered. But it wont be DI any longer. Any ideas on how to handle DI when using Spring Quartz on JDBC Store for clustering.

kiran
  • 2,280
  • 2
  • 23
  • 30

1 Answers1

2

This answer is the best I have found these kind of issues: inject bean reference in quartz job

Basic idea is to extend the SpringBeanJobFactory, inject application context in that new factory, and upon creation of the job, autowire any bean required.

Tested and it works like a charm.

Community
  • 1
  • 1
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117
  • This answer should be accepted. An example can be found in this [blog](http://geekspearls.blogspot.com.au/2015/08/spring-quartz-integration-example-3.html). Take a look at the third way. – Andrew Liu Aug 16 '15 at 07:30
  • A bit late but It does work with RAM job for me, but it does not with JDBC. Guillaume Polet have you tested with JDBC? – Arunas Jan 19 '18 at 08:37
  • @Arunas I have only tested this with JDBC and it works great – Guillaume Polet Jan 21 '18 at 15:27