Spring 整合quartz

记录一下现在新公司的牛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/beans
	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context.xsd
	http://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);
	@Autowired
	ApplicationService applicationService;
	
	public void run() {
		logger.debug("------清理临时文件夹  开始-----");
		applicationService.cleanTempFolder();
		logger.debug("------清理临时文件夹  完成-----");
	}

}


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

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


转一个quartz的表达式

点击打开链接




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值