zoukankan      html  css  js  c++  java
  • 项目总结08:spring quartz 定时器Demo

      

    将定时器用到的quartz.jar放在lip文件下

    quartz.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:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    	                       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    	                       http://www.springframework.org/schema/context 
    	                       http://www.springframework.org/schema/context/spring-context-3.2.xsd">
    	<!--映射-->
    	<bean id= "TimedTask" class ="com.blue.yanxishe.service.timer.TimedTask"/>  
    	<!--自动推送跟踪日志3天未跟新提醒-->
    	<bean id="autoTailLogRemind" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    		<property name="targetObject" ref="TimedTask"/>
    		<property name="targetMethod" value="autoTailLogRemind"/>
    	</bean>
    	<bean id="autoTailLogRemindTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
    		<property name="jobDetail" ref="autoTailLogRemind"/>
    		<property name="cronExpression" value="0 0 0 * * ?"/> 
    	</bean>
    	<!--自动推送排期逾期提醒-->
    	<bean id="autoScheduOverdueRemind" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  //定义JobDetail,即定时任务
    <property name="targetObject" ref="TimedTask"/> //目标类是TimeTask <property name="targetMethod" value="autoScheduOverdueRemind"/> //目标方法时TimeTask类下的autoScheduOverueRemind方法 </bean> <bean id="autoScheduOverdueRemindTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> //配置触发条件 <property name="jobDetail" ref="autoScheduOverdueRemind"/> //关联需要执行的任务 <property name="cronExpression" value="0 0 0 * * ?"/> //设置定义条件,这里"0 0 0 * * ?",表示每天00:00执行一次 </bean>
    <!-- 启动触发器的配置开始--> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="autoTailLogRemindTrigger" /> //关联需要执行的任务设置 <ref bean="autoScheduOverdueRemindTrigger" /> </list> </property> </bean> </beans>

     web.xml(部分) 

    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			classpath:spring/context.xml
    			classpath:spring/context-shiro.xml
    			classpath:spring/context-redis.xml
    			classpath:spring/quartz.xml
    		</param-value>
    	</context-param>
    

      TimedTask.java(完整)

    package com.blue.yanxishe.service.timer;
    
    import java.io.Serializable;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import com.blue.common.exception.ServerSqlErrorException;
    import com.blue.yanxishe.service.shop.ShopMessageService;
    
    @Service
    public class TimedTask implements Serializable{
    	
    	@Autowired
    	private ShopMessageService shopMessageService;
    	
    	public void autoTailLogRemind() throws ServerSqlErrorException{
    		shopMessageService.getTailLogRemind();
    		System.out.println(" getTailLogRemind() was running!!");
    	}
    	
    	public void autoScheduOverdueRemind() throws ServerSqlErrorException{
    		shopMessageService.getScheduOverdueRemind();
    		System.out.println(" getScheduOverdueRemind() was running!!");
    	}
    }
    

      

      
  • 相关阅读:
    jquery 添加关键字小插件
    打印出所有每一位都与其他位不重复的自然数
    尾递归版,斐波那契数列
    如何在移动端宽度自适应实现正方型?
    css隐藏元素的六类13种方法
    如何给行内元素设置宽高?
    css实现垂直水平居中的方法
    pwa
    目录树生成工具treer
    服务端返回的json数据,导致前端报错的原因及解决方法
  • 原文地址:https://www.cnblogs.com/wobuchifanqie/p/7532354.html
Copyright © 2011-2022 走看看