我可以将CDI注入石英调度程序作业吗? [英] can I use CDI injection into quartz-scheduler jobs?
问题描述
我使用Glassfish和CDI进行注射,(主要是)成功。我似乎无法让Quartz工作与注释bean一起工作,注释中注有 @Inject
永远不会被注入。
I'm using Glassfish and CDI for injection, (mostly) successfully. I can't seem to get Quartz jobs to work with injection- beans annotated with @Inject
never get injected.
是否Quartz使用某种不同的类加载器来防止注入发生?
Is Quartz using some kind of different classloader that's preventing injection from happening?
我在我的web.xml中配置Quartz:
I'm configuring Quartz like so in my web.xml:
<context-param>
<param-name>quartz:config-file</param-name>
<param-value>quartz.properties</param-value>
</context-param>
<context-param>
<param-name>quartz:shutdown-on-unload</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>quartz:wait-on-shutdown</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>quartz:start-scheduler-on-load</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>
我的quartz.properties看起来像:
My quartz.properties looks like:
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.scheduler.instanceId = 1
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz-config.xml
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
推荐答案
你需要自己实现org.quartz.spi.JobFactory,它知道如何使用你的应用程序n的CDI实例化作业类并注入它们。
You will need to make your own implementation of org.quartz.spi.JobFactory that knows how to use your application's CDI to instantiate the jobs classes and inject them.
这篇关于我可以将CDI注入石英调度程序作业吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!