两个定时任务(spring)

package com.rj.message.action;

public class TimerAction {

/**
* 月报定时提醒
*/
public void monthWarn(){
Sysyem.out.println("月报定时提醒");
}

/**
* 年报定时提醒
*/
public void yearWarn(){
Sysyem.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!-- 要调用的工作类 -->
<bean id="monthWarn" class="com.rj.message.action.TimerAction"></bean>
<bean id="yearWarn" class="com.rj.message.action.TimerAction"></bean>

<!-- 定义调用对象和调用对象的方法 -->
<bean id="jobtask1"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="monthWarn" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>monthWarn</value>
</property>
</bean>
<bean id="jobtask2"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="yearWarn" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>yearWarn</value>
</property>
</bean>
<!-- 定义触发时间 -->
<bean id="doTime1" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobtask1" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 30 08 10 * ?</value> <!--  设置每月10号8点半进行提醒上报月报 -->
</property>
</bean>
<bean id="doTime2" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobtask2" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0 30 08 10 1 ?</value> <!--  设置每年1月10号8点半进行提醒上报月报 -->
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doTime1" />
<ref bean="doTime2" />
</list>
</property>
</bean>
</beans>




猜你喜欢

转载自ljm1227134894.iteye.com/blog/1889051