配置文件位置:
配置文件内容:(此配置是定义两个调度的配置)
<?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:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
">
<!-- Timer schedule -->
<!--要调度的对象-->
<bean id="msgJobBean" class="com.cn.scheduler.MsgScheduler" />
<bean id="msgJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="msgJobBean" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<bean id="msgJobBean1" class="com.cn.scheduler.EventScheduler" />
<bean id="msgJobDetail1"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="msgJobBean1" />
<property name="targetMethod" value="execute" />
<property name="concurrent" value="false" />
</bean>
<!-- 定制化时间 -->
<bean id="tmpTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="msgJobDetail"></ref>
</property>
<property name="cronExpression">
<value>0 0 2 * * ?</value> <!--每天凌晨两点执行 -->
</property>
</bean>
<bean id="tmpTrigger1"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="msgJobDetail1" />
<property name="startDelay" value="0" /><!-- 调度工厂实例化后,经过0秒开始执行调度 -->
<property name="repeatInterval" value="1000" /><!-- 每1秒调度一次 -->
</bean>
<!-- 将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean
class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
lazy-init="false">
<property name="triggers">
<list>
<ref bean="tmpTrigger" />
<ref bean="tmpTrigger1" />
</list>
</property>
</bean>
</beans>
代码:
package com.cn.cncc.scheduler;
/**
* @name MsgScheduler
* @description 定时
* @author hjr
* @createDate 2017-03-23
*/
public class MsgScheduler {
public void execute(){
System.out.println("调度");
}
}
最后,在web.xml中读取配置文件
来源:CSDN
作者:dewffgqd
链接:https://blog.csdn.net/dewffgqd/article/details/68059800