2013-02-18 92 views
2

我試圖解決避免長時間加載默認quartz.properties文件的問題。希望有人能在這裏舉手。非常感謝!web.xml中的Quartz屬性文件配置及其位置

基本上,我已經閱讀了許多關於這個問題的文章,而他們的解決方案並沒有解決我的問題。我已經把quartz.properties WEB-INF/classes目錄下的文件,並使用上下文偵聽以下是我在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>true</param-value> 
</context-param> 

<context-param> 
    <param-name>quartz:start-on-load</param-name> 
    <param-value>true</param-value> 
</context-param> 

<listener> 
    <listener-class> 
     org.quartz.ee.servlet.QuartzInitializerListener 
    </listener-class> 
</listener> 

結果仍然顯示是這樣的:

[INFO] 18 Feb 06:37:29.218 PM main [org.quartz.impl.StdSchedulerFactory] 
Using default implementation for ThreadExecutor 

[INFO] 18 Feb 06:37:29.265 PM main [org.quartz.core.SchedulerSignalerImpl] 
Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 

[INFO] 18 Feb 06:37:29.265 PM main [org.quartz.core.QuartzScheduler] 
Quartz Scheduler v.2.1.6 created. 

[INFO] 18 Feb 06:37:29.265 PM main [org.quartz.simpl.RAMJobStore] 
RAMJobStore initialized. 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.core.QuartzScheduler] 
Scheduler meta-data: Quartz Scheduler (v2.1.6) 'MyQuartzTest' with instanceId  'NON_CLUSTERED' 
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. 
NOT STARTED. 
Currently in standby mode. 
Number of jobs executed: 0 
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 12 threads. 
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.impl.StdSchedulerFactory] 
Quartz scheduler 'MyQuartzTest' initialized from default resource file in Quartz package: 'quartz.properties' 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.impl.StdSchedulerFactory] 
Quartz scheduler version: 2.1.6 

[INFO] 18 Feb 06:37:29.281 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED started. 

[INFO] 18 Feb 06:37:29.312 PM MyQuartzTest_Worker-1 [org.quartz.examples.example1.HelloJob] 
Hello World! - Mon Feb 18 18:37:29 GMT+08:00 2013 

[INFO] 18 Feb 06:38:09.296 PM MyQuartzTest_Worker-2 [org.quartz.examples.example1.HelloJob] 
Hello World! - Mon Feb 18 18:38:09 GMT+08:00 2013 

[INFO] 18 Feb 06:38:29.296 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED shutting down. 

[INFO] 18 Feb 06:38:29.296 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED paused. 

[INFO] 18 Feb 06:38:29.296 PM main [org.quartz.core.QuartzScheduler] 
Scheduler MyQuartzTest_$_NON_CLUSTERED shutdown complete. 

另一個迷惑我有,如果它真的加載了默認的quartz.properties文件,那麼爲什麼線程池和調度程序名稱是根據我的自定義quartz.properties文件正確設置的?

另一方面,我也試着根據Quartz的官方文檔設置quartz.properties文件的不同路徑:QuartzInitializerListner。例如:

<context-param> 
    <param-name>quartz:config-file</param-name> 
    <param-value>/MyProject/WEB-INF/my_quartz.properties</param-value> 
</context-param> 

結果顯示更糟。這將完全是默認設置。因此,我現在很迷茫。請詳細說明這種情況的根本原因。非常感謝你!

回答

0

我解決了這個問題,將 quartz.properties放在我的資源文件夾(src/main/resources)中。

你的背景下帕拉姆應該是這樣的:

<context-param> 
    <param-name>quartz:config-file</param-name> 
    <param-value>quartz.properties</param-value> 
</context-param> 

看看石英代碼:

InputStream is = null; 
Properties props = new Properties(); 
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); 

其中是屬性文件。

因此,它會嘗試將文件作爲Stream。請檢查Java文檔:

https://docs.oracle.com/javase/7/docs/api/java/lang/ClassLoader.html

...有樂趣