您的位置:首页 > 编程语言 > Java开发

spring跟QuartZ整合

2014-11-21 16:50 309 查看
package com.chengxi.qs.service;

/***
* 执行的业务逻辑类
* @author wzh
*
*/
public class JobTask {
public void work(){
System.out.println("正在调度任务...");
}
}

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/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 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 
<!--
<bean id="user11" class="com.chengxi.qs.model.User"/>
-->
<!-- 需要调用的工作类 -->
<bean id="jobTaskTest" class="com.chengxi.qs.service.JobTask"></bean>

<!-- 定义调用对象和调用方法 -->
<bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="jobTaskTest"/>
</property>

<!-- 调用类中的方法  -->
<property name="targetMethod">
<value>work</value>
</property>
</bean>

<!-- 定义触发时间 -->
<bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobtask"/>
</property>

<!-- corn表达式 -->
<property name="cronExpression">
<value>10/5 * * * * ?</value>
</property>
</bean>

<!-- 总管理类  如果将lazy-init='false' 那么容器启动就会执行调度程序 -->
<bean id="startQuartz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doTime"/>
</list>
</property>
</bean>
</beans>
这是需要的jar包不要少添加了

然后在src目录下记得添加

log4j.properties

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: