Quartz作业未通过XMLSchedulingDataProcessorPlugin启动

时间:2018-09-11 08:14:00

标签: java spring quartz-scheduler

已经两天了,我试图弄清楚如何使事情正常进行。我有一个Java Spring应用程序,我想使用XMLSchedulingDataProcessorPlugin在我的应用程序中运行作业。这是我定义的Job类:

public class MyJob implements Job
{
    private final static Logger LOGGER = Logger.getLogger(MyJob.class.getName());

    public MyJob() { 
        System.out.println("My Job");
        LOGGER.log(Level.INFO, "My Job");
    }

    @Override
    public void execute(JobExecutionContext context)
    throws JobExecutionException {
        LOGGER.setLevel(Level.INFO);
        LOGGER.log(Level.INFO, "my job fired");
        System.out.println("my job fired"); 

    }

}

非常简单。以下是我为触发先前定义的作业而定义的quartz.properties文件:

org.quartz.scheduler.instanceName: MySchedulerForMyJob
org.quartz.scheduler.instanceId: AUTO
org.quartz.scheduler.skipUpdateCheck: true

org.quartz.plugin.triggHistory.class: org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobInitializer.class: org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames: quartz_jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound: true
org.quartz.plugin.jobInitializer.scanInterval: 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction: false

org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool 
org.quartz.threadPool.threadCount: 3
org.quartz.threadPool.threadPriority: 5

org.quartz.jobStore.misfireThreshold: 60000
org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore

现在让我们看看我是如何告诉Quartz看如何定义quartz_jobs.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>myJob</name>
            <group>MYJOB_GROUP</group>
            <description>This job is a job</description>
            <job-class>com.myProject.MyJob</job-class>
        </job>
        <trigger>
            <cron>
                <name>myTrigger</name>
                <group>MYTRIGGER_GROUP</group>
                <job-name>myJob</job-name>
                <job-group>MYJOB_GROUP</job-group>
                <!-- trigger every 5 seconds -->
                <cron-expression>0/5 * * * * ?</cron-expression>
            </cron>
        </trigger>
    </schedule>
</job-scheduling-data>

基本上,我期望在启动时看到每隔5秒打印一次“我的工作被解雇”的消息。我没有看到任何类似的信息,这表明该工作没有开始。以下是我在控制台中得到的输出:

2018-09-11 10:02:39,944 - INFO  - [org.quartz.core.SchedulerSignalerImpl] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2018-09-11 10:02:39,944 - INFO  - [org.quartz.core.QuartzScheduler] - Quartz Scheduler v.1.6.3 created.
2018-09-11 10:02:39,945 - INFO  - [org.quartz.simpl.RAMJobStore] - RAMJobStore initialized.
2018-09-11 10:02:39,945 - INFO  - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' initialized from an externally provided properties instance.
2018-09-11 10:02:39,945 - INFO  - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler version: 1.6.3
2018-09-11 10:02:39,946 - INFO  - [org.quartz.core.QuartzScheduler] - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@ad570f2
2018-09-11 10:02:40,220 - WARN  - [org.apache.axis.utils.JavaUtils] - Unable to find required classes (javax.activation.DataHandler and javax.mail.internet.MimeMultipart). Attachment support is disabled.
2018-09-11 10:02:40,319 - INFO  - [org.quartz.core.QuartzScheduler] - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED started.
Quartz Initializer Servlet loaded, initializing Scheduler...
2018-09-11 10:02:40,326 - INFO  - [org.quartz.core.SchedulerSignalerImpl] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
2018-09-11 10:02:40,326 - INFO  - [org.quartz.core.QuartzScheduler] - Quartz Scheduler v.1.6.3 created.
2018-09-11 10:02:40,326 - INFO  - [org.quartz.simpl.RAMJobStore] - RAMJobStore initialized.
2018-09-11 10:02:40,326 - INFO  - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler 'MySchedulerForMyJob' initialized from default resource file in Quartz package: 'quartz.properties'
2018-09-11 10:02:40,326 - INFO  - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler version: 1.6.3
2018-09-11 10:02:40,326 - INFO  - [org.quartz.core.QuartzScheduler] - Scheduler MPListScheduler_$_NON_CLUSTERED started.
Scheduler has been started...
Storing the Quartz Scheduler Factory in the servlet context at key: org.quartz.impl.StdSchedulerFactory.KEY

这建议我正确读取quartz.properties文件,因为它说2018-09-11 10:02:40,326 - INFO - [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler 'MySchedulerForMyJob' initialized from default resource file in Quartz package: 'quartz.properties'引用了我在quartz.properties中给出的调度程序的正确名称。

所有这一切可能导致工作无法开始?

1 个答案:

答案 0 :(得分:0)

我想您仍然对quartz.properties有一些问题。我对以下配置有疑问。如果不能解决您的问题,请问

org.quartz.plugin.triggHistory.class:org.quartz.plugins.history.LoggingJobHistoryPlugin

应为`

  

LoggingTriggerHistoryPlugin

`

org.quartz.plugin.triggerHistory.class=org.quartz.plugins.history.LoggingTriggerHistoryPlugin

OR

  

LoggingJobHistoryPlugin

org.quartz.plugin.jobHistory.class=org.quartz.plugins.history.LoggingJobHistoryPlugin

您错误地配置了该属性。看看使用这些功能的情况。 link

否则,首先尝试一个简单的示例,该示例没有任何线程池或日志作业历史记录。有些example。如果可能,请在属性文件中将:更改为=。我知道那不是问题。只需尝试