1. 引入quartz的jar包
2. 建立需要运行的调度的类和方法
package com.baidu.service; import java.util.Date; public class QuartzService{ public void work(){ System.out.println("当前时间:"+new Date().toString()); } }
3.创建调度xml文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true"> <!-- 要调用的工作类 --> <bean id="quartzService" class="com.baidu.service.QuartzService"></bean> <!-- 启动触发器的配置开始 --> <bean name="schedulerFactory" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref local="taskJobTrigger" /> </list> </property> </bean> <!-- 启动触发器的配置结束 --> <!-- job的配置开始 --> <bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="quartzService"></property> <property name="targetMethod" value="work"></property> <property name="concurrent" value="false"></property> </bean> <!-- job的配置结束 --> <!-- 调度的配置开始 --> <bean id="taskJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="myJobDetail" /> </property> <property name="cronExpression"> <value>0/10 * * * * ?</value> </property> </bean> <!-- 调度的配置结束 --> </beans>
4.引入xml(app-context.xml spring的配置文件)
<import resource="app-scheduling.xml"/>
5. web.xml中的配置
<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用,号分隔 此参数用于后面的Spring Context Loader --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/application-context.xml</param-value> </context-param> <!--Spring的ApplicationContext 载入 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
启动tomcat后,如果没有报错的话,就运行work方法了。
相关推荐
关于spring中quartz的配置
Spring中的Quartz配置-Spring-定时器-java定时器.doc
spring-quartz的标准配置文件
Spring Quartz如何动态配置时间
spring 集成quartz定时任务 用数据库实现quartz的集群
针对于spring集成quartz配置进行详细说明,并提供部分简单示例说明配置。
Spring中Quartz详细配置实例+所用包(spring.jar quartz-all-1.6.0.jar log4j-1.2.14.jar commons-collections.jar jta.jar commons-logging.jar)
java + quartz实现定时任务,实现集群配置,在集群环境下多节点运行定时Quartz定任务,就会存在重复处理任务的现象,为解决这一问题,下面我将介绍使用 Quartz 的 TASK ( 12 张表)实例化到数据库,基于数据库自动...
spring注解Quartz定时执行功能
Quartz学习文档 Spring + Quartz配置详细实例 jar包 Quartz时间格式设置
Spring中Quartz任务调度器cronexpression配置说明
Spring中Quartz的配置[总结].pdf
spring 在配置quartz定时任务时所需要的jar包,里面含有两个包quartz-all-1.8.3和commons-logging-1.0.4
spring3 配置quartz定时任务的使用。一个小例子。可直接运行Test.java。就可以启动定时任务。每10秒钟执行一次,可以根据自己配置。
spring quartz 非配置动态定时
NULL 博文链接:https://javaeedevelop.iteye.com/blog/1540461
Quartz2.2.1基于Spring注解方式配置QuartzL,具体过程的效果看博文 http://blog.csdn.net/evankaka/article/details/45400781
NULL 博文链接:https://duanfei.iteye.com/blog/1732839
定时任务demo,Java语言,spring整合quartz配置文件实现定时任务