3

我使用Glassfish和CDI注射,(大部分)成功。我似乎無法讓Quartz作業與注入一起使用,註釋中使用@Inject註釋的bean永遠不會被注入。我可以使用CDI注入石英調度程序作業嗎?

Quartz是否使用某種不同的類加載器來防止注入發生?

我配置石英像這樣在我的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的樣子:

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 
+0

好的描述與CDI擴展在這裏http://jaxenter.com/tutorial-cdi-extension-programming-42972.html – rombow 2013-08-08 08:52:58

回答

2

你需要使自己實現org.quartz的.spi.JobFactory知道如何使用應用程序的CDI實例化作業類並注入它們。

0

github上有一個Quartz CDI集成庫。還沒有嘗試過。