Spring 整合quartz

来源:互联网 发布:股票基本面软件 编辑:程序博客网 时间:2024/06/05 05:04

记录一下现在新公司的牛b框架!


今日又模仿了经理的东西!又是不求甚解。


xxx-project-job.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"default-lazy-init="true"> <!-- 定时任务列表start -->    <bean id="JobSchedules" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">        <property name="triggers">            <list>               <ref bean="recordTimeJobSchedule" />             <ref bean="taobaoMessageErrorHandleJobSchedule" />             <ref bean="cleanTempFolderJobSchedule" />             <ref bean="disabledProductAgentJobSchedule" />            </list>        </property>    </bean><!-- 定时任务列表end --><!-- 记录服务器运行时间任务start--><bean id="recordTimeJobSchedule" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail">            <bean id="RemindJobScheduleInvoker" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">                <property name="targetObject" ref="xxx_recordTimeJob"/>                <property name="targetMethod"><value>perform</value></property>            </bean>        </property>        <property name="cronExpression">             <value>0 1/5 * * * ?</value>          </property></bean><!-- 记录服务器运行时间任务end--><!-- 淘宝消息处理错误重试任务 start--><bean id="taobaoMessageErrorHandleJobSchedule" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail">            <bean id="TaobaoMessageErrorHandleJobScheduleInvoker" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">                <property name="targetObject" ref="xxx_TaobaoMessageErrorHandleJob"/>                <property name="targetMethod"><value>perform</value></property>            </bean>        </property>        <property name="cronExpression">             <value>0 3/5 * * * ?</value>          </property></bean><!-- 淘宝消息处理错误重试任务  end--><!-- 清理临时文件夹 start--><bean id="cleanTempFolderJobSchedule" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail">            <bean id="CleanTempFolderJobScheduleInvoker" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">                <property name="targetObject" ref="xxx_CleanTempFolderJob"/>                <property name="targetMethod"><value>perform</value></property>            </bean>        </property>        <property name="cronExpression">             <value>0 0 0 1 * ?</value>          </property></bean><!-- 清理临时文件夹  end--><!-- 禁用产品 每天一点执行start --><bean id="disabledProductAgentJobSchedule" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail">            <bean id="CleanTempFolderJobScheduleInvoker" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">                <property name="targetObject" ref="xxx_productAgentDisabledJob"/>                <property name="targetMethod"><value>perform</value></property>            </bean>        </property>        <property name="cronExpression">             <value>0 0 1 * * ?</value>          </property></bean><!-- 禁用产品  end--></beans>

执行的Service

package com.xxx.project.job;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.sanwn.framework.core.job.AbstractScheduleJob;import com.sanwn.distribution.basic.ApplicationService;import com.sanwn.distribution.business.service.TradeService;/** */@Service("xxx_CleanTempFolderJob")public class CleanTempFolderJob  extends AbstractScheduleJob {private static Log logger = LogFactory.getLog(CleanTempFolderJob.class);@AutowiredApplicationService applicationService;public void run() {logger.debug("------清理临时文件夹  开始-----");applicationService.cleanTempFolder();logger.debug("------清理临时文件夹  完成-----");}}


当然你要开启注解,获取这个Service

<context:component-scan base-package="com.xxxx"/>


转一个quartz的表达式

点击打开链接




原创粉丝点击