- 浏览: 5992 次
最新评论
(一)注意:
1.quartz.jar用1.6版本的,版本问题纠结很久
2.所用到jar:
commons-beanutils.jar
commons-collections-3.1.jar
commons-digester.jar
commons-logging.jar
jta-1.1.jar
quartz-1.6.5.jar
(二)HelloWorldQuartzJob.java
package com.quartz;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloWorldQuartzJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println("");
System.out.println("==============================");
System.out.println("Time("+formateDate(new Date())+") - Hello World Quartz (xml)");
System.out.println("==============================");
System.out.println("");
}
static String formateDate(Date date) {
SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
return formate.format(date);
}
}
(三)配置job.xml
<?xml version='1.0' encoding='utf-8'?>
<quartz>
<job>
<job-detail>
<name>test</name>
<group>DEFAULT</group>
<description>testJobhere</description>
<job-class>com.quartz.HelloWorldQuartzJob</job-class>
</job-detail>
<trigger>
<cron>
<name>testTrigger</name>
<group>DEFAULT</group>
<job-name>test</job-name>
<job-group>DEFALUT</job-group>
<cron-expression>0/5 * * * * ?</cron-expression>
</cron>
</trigger>
</job>
</quartz>
(四)quartz.properties
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
#============================================================================
# Configure Plugins
#============================================================================
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.fileNames = conf/jobs.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
(五)启动类
package startup;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
public class Main {
public static void main(String[] args) throws SchedulerException {
//First we must get a reference to a scheduler
StdSchedulerFactory sf = getSchedulerFactory("conf/quartz.properties");
Scheduler sched = sf.getScheduler();
sched.start();
}
protected static StdSchedulerFactory getSchedulerFactory(String configFile)
throws SchedulerException
{
StdSchedulerFactory factory;
if (configFile != null)
factory = new StdSchedulerFactory(configFile);
else {
factory = new StdSchedulerFactory();
}
return factory;
}
}
调试结果如下:
三月 09, 2017 5:46:53 下午 org.quartz.core.SchedulerSignalerImpl <init>
信息: Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
三月 09, 2017 5:46:53 下午 org.quartz.core.QuartzScheduler <init>
信息: Quartz Scheduler v.1.6.5 created.
三月 09, 2017 5:46:53 下午 org.quartz.plugins.xml.JobInitializationPlugin initialize
信息: Registering Quartz Job Initialization Plug-in.
三月 09, 2017 5:46:53 下午 org.quartz.simpl.RAMJobStore initialize
信息: RAMJobStore initialized.
三月 09, 2017 5:46:53 下午 org.quartz.impl.StdSchedulerFactory instantiate
信息: Quartz scheduler 'MyScheduler' initialized from the specified file : 'conf/quartz.properties'
三月 09, 2017 5:46:53 下午 org.quartz.impl.StdSchedulerFactory instantiate
信息: Quartz scheduler version: 1.6.5
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor processFile
信息: Parsing XML file: conf/jobs.xml with systemId: conf/jobs.xml validating: false validating schema: jar:file:/D:/User/ee-keeper/workspace/quartz-example/lib/quartz-1.6.5.jar!/org/quartz/xml/job_scheduling_data_1_5.xsd
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor scheduleJobs
信息: Scheduling 1 parsed jobs.
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor scheduleJob
信息: Adding job: DEFAULT.test
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor scheduleJobs
信息: 1 scheduled jobs.
三月 09, 2017 5:46:53 下午 org.quartz.core.QuartzScheduler start
信息: Scheduler MyScheduler_$_NON_CLUSTERED started.
三月 09, 2017 5:46:53 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:46:53 03/09/2017
三月 09, 2017 5:46:53 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:46:53 03/09/2017 and reports: null
三月 09, 2017 5:46:55 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:46:55 03/09/2017
==============================
Time(2017-03-09 17:46:55.004) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:46:55 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:46:55 03/09/2017 and reports: null
三月 09, 2017 5:47:00 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:00 03/09/2017
==============================
Time(2017-03-09 17:47:00.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:00 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:00 03/09/2017 and reports: null
三月 09, 2017 5:47:03 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:47:03 03/09/2017
三月 09, 2017 5:47:03 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:47:03 03/09/2017 and reports: null
==============================
Time(2017-03-09 17:47:05.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:05 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:05 03/09/2017
三月 09, 2017 5:47:05 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:05 03/09/2017 and reports: null
三月 09, 2017 5:47:10 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:10 03/09/2017
==============================
Time(2017-03-09 17:47:10.004) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:10 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:10 03/09/2017 and reports: null
三月 09, 2017 5:47:13 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:47:13 03/09/2017
三月 09, 2017 5:47:13 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:47:13 03/09/2017 and reports: null
==============================
三月 09, 2017 5:47:15 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:15 03/09/2017
三月 09, 2017 5:47:15 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:15 03/09/2017 and reports: null
Time(2017-03-09 17:47:15.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:20 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:20 03/09/2017
==============================
Time(2017-03-09 17:47:20.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:20 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:20 03/09/2017 and reports: null
三月 09, 2017 5:47:23 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:47:23 03/09/2017
三月 09, 2017 5:47:23 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:47:23 03/09/2017 and reports: null
==============================
Time(2017-03-09 17:47:25.004) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:25 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:25 03/09/2017
三月 09, 2017 5:47:25 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:25 03/09/2017 and reports: null
1.quartz.jar用1.6版本的,版本问题纠结很久
2.所用到jar:
commons-beanutils.jar
commons-collections-3.1.jar
commons-digester.jar
commons-logging.jar
jta-1.1.jar
quartz-1.6.5.jar
(二)HelloWorldQuartzJob.java
package com.quartz;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloWorldQuartzJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println("");
System.out.println("==============================");
System.out.println("Time("+formateDate(new Date())+") - Hello World Quartz (xml)");
System.out.println("==============================");
System.out.println("");
}
static String formateDate(Date date) {
SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
return formate.format(date);
}
}
(三)配置job.xml
<?xml version='1.0' encoding='utf-8'?>
<quartz>
<job>
<job-detail>
<name>test</name>
<group>DEFAULT</group>
<description>testJobhere</description>
<job-class>com.quartz.HelloWorldQuartzJob</job-class>
</job-detail>
<trigger>
<cron>
<name>testTrigger</name>
<group>DEFAULT</group>
<job-name>test</job-name>
<job-group>DEFALUT</job-group>
<cron-expression>0/5 * * * * ?</cron-expression>
</cron>
</trigger>
</job>
</quartz>
(四)quartz.properties
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
#============================================================================
# Configure Plugins
#============================================================================
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.fileNames = conf/jobs.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
(五)启动类
package startup;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
public class Main {
public static void main(String[] args) throws SchedulerException {
//First we must get a reference to a scheduler
StdSchedulerFactory sf = getSchedulerFactory("conf/quartz.properties");
Scheduler sched = sf.getScheduler();
sched.start();
}
protected static StdSchedulerFactory getSchedulerFactory(String configFile)
throws SchedulerException
{
StdSchedulerFactory factory;
if (configFile != null)
factory = new StdSchedulerFactory(configFile);
else {
factory = new StdSchedulerFactory();
}
return factory;
}
}
调试结果如下:
三月 09, 2017 5:46:53 下午 org.quartz.core.SchedulerSignalerImpl <init>
信息: Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
三月 09, 2017 5:46:53 下午 org.quartz.core.QuartzScheduler <init>
信息: Quartz Scheduler v.1.6.5 created.
三月 09, 2017 5:46:53 下午 org.quartz.plugins.xml.JobInitializationPlugin initialize
信息: Registering Quartz Job Initialization Plug-in.
三月 09, 2017 5:46:53 下午 org.quartz.simpl.RAMJobStore initialize
信息: RAMJobStore initialized.
三月 09, 2017 5:46:53 下午 org.quartz.impl.StdSchedulerFactory instantiate
信息: Quartz scheduler 'MyScheduler' initialized from the specified file : 'conf/quartz.properties'
三月 09, 2017 5:46:53 下午 org.quartz.impl.StdSchedulerFactory instantiate
信息: Quartz scheduler version: 1.6.5
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor processFile
信息: Parsing XML file: conf/jobs.xml with systemId: conf/jobs.xml validating: false validating schema: jar:file:/D:/User/ee-keeper/workspace/quartz-example/lib/quartz-1.6.5.jar!/org/quartz/xml/job_scheduling_data_1_5.xsd
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor scheduleJobs
信息: Scheduling 1 parsed jobs.
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor scheduleJob
信息: Adding job: DEFAULT.test
三月 09, 2017 5:46:53 下午 org.quartz.xml.JobSchedulingDataProcessor scheduleJobs
信息: 1 scheduled jobs.
三月 09, 2017 5:46:53 下午 org.quartz.core.QuartzScheduler start
信息: Scheduler MyScheduler_$_NON_CLUSTERED started.
三月 09, 2017 5:46:53 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:46:53 03/09/2017
三月 09, 2017 5:46:53 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:46:53 03/09/2017 and reports: null
三月 09, 2017 5:46:55 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:46:55 03/09/2017
==============================
Time(2017-03-09 17:46:55.004) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:46:55 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:46:55 03/09/2017 and reports: null
三月 09, 2017 5:47:00 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:00 03/09/2017
==============================
Time(2017-03-09 17:47:00.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:00 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:00 03/09/2017 and reports: null
三月 09, 2017 5:47:03 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:47:03 03/09/2017
三月 09, 2017 5:47:03 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:47:03 03/09/2017 and reports: null
==============================
Time(2017-03-09 17:47:05.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:05 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:05 03/09/2017
三月 09, 2017 5:47:05 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:05 03/09/2017 and reports: null
三月 09, 2017 5:47:10 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:10 03/09/2017
==============================
Time(2017-03-09 17:47:10.004) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:10 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:10 03/09/2017 and reports: null
三月 09, 2017 5:47:13 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:47:13 03/09/2017
三月 09, 2017 5:47:13 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:47:13 03/09/2017 and reports: null
==============================
三月 09, 2017 5:47:15 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:15 03/09/2017
三月 09, 2017 5:47:15 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:15 03/09/2017 and reports: null
Time(2017-03-09 17:47:15.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:20 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:20 03/09/2017
==============================
Time(2017-03-09 17:47:20.003) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:20 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:20 03/09/2017 and reports: null
三月 09, 2017 5:47:23 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml fired (by trigger JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml) at: 17:47:23 03/09/2017
三月 09, 2017 5:47:23 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer_jobs_xml execution complete at 17:47:23 03/09/2017 and reports: null
==============================
Time(2017-03-09 17:47:25.004) - Hello World Quartz (xml)
==============================
三月 09, 2017 5:47:25 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobToBeExecuted
信息: Job DEFAULT.test fired (by trigger DEFAULT.testTrigger) at: 17:47:25 03/09/2017
三月 09, 2017 5:47:25 下午 org.quartz.plugins.history.LoggingJobHistoryPlugin jobWasExecuted
信息: Job DEFAULT.test execution complete at 17:47:25 03/09/2017 and reports: null
相关推荐
【标题】"Spring+Quartz+Maven项目实例"是一个基于Spring框架集成Quartz作业调度库的实战项目,采用Maven作为构建工具。这个实例旨在展示如何在Java应用程序中实现定时任务,支持两种运行模式,既可以直接以独立的...
在提供的压缩包文件“quartz项目资料”中,可能包含了关于如何设置Quartz与Spring集成的详细示例代码、数据库脚本、配置文件等,你可以进一步学习和参考。通过实践这些资料,你将能够更好地理解和掌握如何利用Quartz...
【描述】"spring+quartz配置的定时器 可以动态添加任务"意味着我们可以利用Spring的配置能力,灵活地在运行时动态地添加、修改或删除Quartz作业。这种动态性是通过Spring容器管理和Quartz JobDetail以及Trigger对象...
Java Spring 框架是企业级应用开发的热门选择,它提供了一种全面的依赖注入(Dependency Injection,DI)和面向切面编程(Aspect Oriented Programming,AOP)的解决方案,使得开发者能够更加专注于业务逻辑的实现,...
本篇将深入探讨如何使用Java和Spring Quartz来配置和调度cron任务。 首先,我们需要理解Spring Quartz的核心组件。`Job`接口代表一个可调度的任务,而`Trigger`则定义了任务的执行时间。在Spring中,我们通常使用`...
`resource` 文件夹通常用于放置非 Java 资源,比如 Spring 的 XML 配置文件、日志配置或 Quartz 的配置文件(如 `quartz.properties`)。 `WebContent` 文件夹是标准的 Web 项目结构,包含静态资源(如 HTML、CSS、...
标题 "spring+mybatis+quartz" 暗示了我们正在探讨一个使用Spring框架、MyBatis持久层框架和Quartz作业调度器的集成应用。这个组合在企业级Java应用中非常常见,用于实现复杂的数据操作、服务管理和定时任务。 ...
Spring Quartz提供了声明式配置,可以将作业和触发器定义在XML配置文件或Java配置类中,并且可以通过Spring的依赖注入(DI)来获取和注入所需的bean。 结合这两个知识点,我们可以将动态加载属性文件与Spring ...
在本示例中,我们将探讨如何在Spring应用中配置和使用Quartz,以及通过示例代码来理解其工作原理。 首先,我们需要在项目中引入Quartz的依赖。如果你使用的是Maven,可以在pom.xml文件中添加以下依赖: ```xml ...
标题提到“spring+quartz需要的4个jar包”,这意味着我们可以用最少的依赖来集成这两个库。通常,Spring和Quartz的集成会涉及以下关键的jar文件: 1. **Spring框架的核心库**:`spring-context.jar` - 这个jar包含...
- 在`web.xml`中,通过`contextConfigLocation`参数指定了Spring配置文件的位置,这样Spring会自动加载`applicationContext-quartz.xml`。 3. **业务逻辑**: - `SysScheduleServiceImpl`类实现了`...
// 加载Spring配置 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); // 获取Scheduler Scheduler scheduler = (Scheduler) context.getBean(...
- 在 `web.xml` 中,设置 Spring 的上下文加载监听器 `ContextLoaderListener` 以启动 Spring 容器,并指定配置文件的位置。确保 `web.xml` 中的 Spring 配置文件设置在监听器之前,以避免配置顺序错误。 ```xml ...
在题目中的代码中,`SchedulerFactoryBean` 被配置为非懒加载,这意味着当 Spring 上下文初始化时,Quartz 调度器就会被创建并准备好调度任务。 ```xml <bean name="quartzScheduler" class="org.springframework....
"shiro+SpringMVC+Spring+mybatis+maven+mybatis 自动刷新+Quartz scheduler 定时器"是一个常见的技术栈组合,每个组件都有其特定的功能和作用。 1. **Shiro**:Apache Shiro 是一个强大且易用的Java安全框架,提供...
在 Spring 中,通过 XML 或 Java 配置类来定义 Quartz 任务是非常常见的做法。以下是一种简单的示例: ```xml <bean id="jobDetail" class="org.springframework.scheduling.quartz....
在Java世界中,Spring框架是企业级应用开发的首选,而Quartz则是一个强大的作业调度库,用于执行定时任务。本教程将详细讲解如何结合Spring和Quartz来创建和管理定时任务。 首先,理解Spring与Quartz的集成原理。...
其中,Spring3的注解驱动特性使得代码更加简洁,无需XML配置即可实现组件的装配。Spring与Struts2的集成,可以实现请求的调度和业务逻辑的处理,同时Spring的事务管理能确保数据操作的一致性。 MyBatis3.05是持久层...
2. **配置 Quartz**:在 Spring 的配置文件(如 `applicationContext.xml`)中,声明 Quartz 的 JobStore(用于存储任务和触发器信息),ThreadPool(用于执行任务的线程池)以及 SchedulerFactoryBean(Spring 对 ...