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!!");
    	}
    }
    

      

      
  • 相关阅读:
    less引入、关键字、条件表达式、循环、合并属性
    less 嵌套规则、运算、函数、命名空间
    初识less
    ligerui_实际项目_001:利用ligerLayout、ligerAccordion实现可折叠的菜单效果
    ligerUI_入门_001_设置文本能否被编辑、事件
    AJax 学习笔记二(onreadystatechange的作用)
    JSon_零基础_008_将JSon格式的"数组"字符串转换为List集合
    JSon_零基础_007_将JSon格式的"数组"字符串转换为Java对象"数组"
    JSon_零基础_006_将JSon格式的字符串转换为Java对象
    JSon_零基础_005_将po(bean)对象集合List转换为JSon格式的对象字符串,返回给界面
  • 原文地址:https://www.cnblogs.com/wobuchifanqie/p/7532354.html
Copyright © 2011-2022 走看看