我想通过xml配置和Tomcat Server一起运行Quartzjob。但是当我启动Tomcat时,我的工作根本没有启动。 任何人都可以帮忙吗? 这是我的代码:
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>
</web-app>
MyJob.java
package com.cron;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class MyJob implements Job {
public void execute(JobExecutionContext context)
throws JobExecutionException {
System.out.println("Cron executing ");
}
}
项目src文件夹下的quartz-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData
http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">
<schedule>
<job>
<name>FirstJob</name>
<group>DummyGroup</group>
<description>This is FirstJob</description>
<job-class>com.cron.MyJob</job-class>
</job>
<trigger>
<cron>
<name>dummyTrigger</name>
<job-name>FirstJob</job-name>
<job-group>GroupDummy</job-group>
<!-- It will run every 2 seconds -->
<cron-expression>0/2 * * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
项目src文件夹下的quartz.properties文件
org.quartz.scheduler.instanceName = MyScheduler
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.failOnFileNotFound = true
当我启动Tomcat服务器时,它显示在下面的日志
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Apr 12, 2015 4:39:28 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8441
Apr 12, 2015 4:39:28 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8442
Apr 12, 2015 4:39:28 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/46 config=null
Apr 12, 2015 4:39:28 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1208 ms
我在下面使用的JAR文件列表:
quartz-2.2.1.jar
quartz-jobs-2.2.1.jar
slf4j-api-1.7.5.jar
jta-1.1.jar
答案 0 :(得分:0)
我遇到了org.quartz.ee.servlet.QuartzInitializerListener的问题而我正在使用servlet方法。
<!--Quartz-->
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<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>
<init-param>
<param-name>config-file</param-name>
<param-value>META-INF/quartz.properties</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>