JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Tools  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Quartz+Tomcat7 無法初始化Scheduler
bravomao





發文: 22
積分: 0
於 2017-04-28 11:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位先進,
小弟最近開始接觸Quartz,想在我原本用的Tomcat上面開始。在網路上找了一些分享之後做了一些設定,但是遇到Scheduler無法初始化的問題,研究了很久但是始終無法正常運作,因此想在這請教有經驗的先進指點。

我的做法是在Tomcat裡面新增或修改了幾個文件,例如:
web.xml中新增下面的文字
<servlet>
    <servlet-name>QuartzInitializer</servlet-name>
    <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
    <init-param>
      <param-name>config-file</param-name>
      <param-value>Resources/quartz.properties</param-value>
    </init-param>
    <init-param>
      <param-name>shutdown-on-unload</param-name>
      <param-value>true</param-value>
    </init-param>
    <init-param>
      <param-name>start-scheduler-on-load</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

新增一個quartz.properties,內容如下:
org.quartz.jobStore.class=org.quartz.simpl.RAMJobStore
org.quartz.jobStore.misfireThreshold=60000
#org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.failOnFileNotFound=true
org.quartz.plugin.jobInitializer.fileNames=Resources/quartz_data.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs=true
org.quartz.plugin.jobInitializer.validating=false
org.quartz.plugin.jobInitializer.validatingSchema=true
org.quartz.plugin.triggHistory.class=org.quartz.plugins.history.LoggingTriggerHistoryPlugin
org.quartz.plugin.triggHistory.triggerCompleteMessage=Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH\:mm\:ss MM/dd/yyyy} with resulting trigger instruction code\: {9}
org.quartz.plugin.triggHistory.triggerFiredMessage=Trigger {1}.{0} fired job {6}.{5} at\: {4, date, HH\:mm\:ss MM/dd/yyyy}
org.quartz.scheduler.instanceId=1
org.quartz.scheduler.instanceName=sched1
org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount=10
org.quartz.threadPool.threadPriority=5

然後新增了一個quartz_data.xml,內容如下:
<job-scheduling-data version="1.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData" xsi:schemalocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd">
<schedule>
<job>
<name>TestJob</name>
<job-class>tw.com.xxx.utils.JobPrintString</job-class>
</job>
<trigger>
<cron>
<name>CronTestJob</name>
<job-name>TestJob</job-name>
<cron-expression>0/5 * * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>

最後我寫了一個小小的class,內容如下:
package tw.com.xxx.utils;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class JobPrintString implements Job {

  @Override
  public void execute(JobExecutionContext arg0) throws JobExecutionException {
    // TODO Auto-generated method stub
    System.out.println("Job get started to print string here!!!!!");
    try{
      Thread.sleep(5000);      
    }catch(Exception e){
      System.out.println("Error ="+e.getMessage());
    }
  }
}

我的JVM版本是1.7,Quartz版本是2.2.3,下載的幾個JAR我都有放到lib裡面,例如:
c3p0-0.9.1.1.jar
log4j-1.2.16.jar
quartz-2.2.3.jar
quartz-jobs-2.2.3.jar
slf4j-api-1.7.7.jar
slf4j-log4j12-1.7.7.jar

最後我要啟動tomcat時遇到了一個錯誤訊息如下:
資訊: QuartzInitializer: Quartz Initializer Servlet loaded, initializing Scheduler...
四月 28, 2017 7:08:18 下午 org.apache.catalina.core.ApplicationContext log
資訊: QuartzInitializer: Quartz Scheduler failed to initialize: org.quartz.SchedulerException: JobStore SchedulerPlugin 'org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin' props could not be configured. [See nested exception: java.lang.NoSuchMethodException: No setter for property 'overWriteExistingJobs']
四月 28, 2017 7:08:18 下午 org.apache.catalina.core.StandardContext loadOnStartup
嚴重: Servlet /APMDemoTomcat threw load() exception
java.lang.NoSuchMethodException: No setter for property 'overWriteExistingJobs'
  at org.quartz.impl.StdSchedulerFactory.setBeanProps(StdSchedulerFactory.java:1413)
  at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1045)
  at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1525)
  at org.quartz.ee.servlet.QuartzInitializerServlet.init(QuartzInitializerServlet.java:187)
  at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1279)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1192)
  at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
  at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

雖然看起來是nosuchmethod的錯誤,但我覺得我在設定上應該有失誤的地方。
如果我把quartz.propertiesˊ中的
org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
改成用
org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.JobInitializationPlugin

錯誤訊息會變成如下:
資訊: QuartzInitializer: Quartz Initializer Servlet loaded, initializing Scheduler...
四月 28, 2017 7:19:06 下午 org.apache.catalina.core.ApplicationContext log
資訊: QuartzInitializer: Quartz Scheduler failed to initialize: org.quartz.SchedulerException: SchedulerPlugin class 'org.quartz.plugins.xml.JobInitializationPlugin' could not be instantiated. [See nested exception: java.lang.ClassNotFoundException: org.quartz.plugins.xml.JobInitializationPlugin]
四月 28, 2017 7:19:06 下午 org.apache.catalina.core.StandardContext loadOnStartup
嚴重: Servlet /APMDemoTomcat threw load() exception
java.lang.ClassNotFoundException: org.quartz.plugins.xml.JobInitializationPlugin
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
  at org.quartz.simpl.InitThreadContextClassLoadHelper.loadClass(InitThreadContextClassLoadHelper.java:72)
  at org.quartz.simpl.CascadingClassLoadHelper.loadClass(CascadingClassLoadHelper.java:114)
  at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1036)
  at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1525)
  at org.quartz.ee.servlet.QuartzInitializerServlet.init(QuartzInitializerServlet.java:187)
  at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1279)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1192)
  at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
  at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
  at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

因此想請教我是哪裡的觀念有錯? 我要怎麼設定才能讓Quartz可以照我想的在Tomcat啟動後,每五秒自動在console中印出一句話?

非常感謝


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
645 Quartz+Tomcat7 無法初始化Scheduler bravomao 7941 2017-04-28 11:27
» JWorld@TW »  Java Tools

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8