Spring+SpringMVC+MyBatis项目开发定时器

1、用到的jar

pom.xml配置:

<dependency>

    <groupId>org.quartz-scheduler</groupId>

    <artifactId>quartz</artifactId>

    <version>2.3.0</version>

</dependency>

2、配置文件spring-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"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
			http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"
       default-lazy-init="true">
	  <!-- 调用的类 -->
	<bean	id="auditWarningQuartz"	class="chinatelecom.feildata.web.dataAudit.quartz.AuditWarningQuartz" ></bean>
	  <!-- 定时发送短信、邮件 -->
<bean	id="autoSendMailAndShortMsgTask"	class= "org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
	 <property name="targetObject" ref= "auditWarningQuartz"></property>
	  <property name="targetMethod" value= "autoSendMailAndShortMsg"></property>
	  <property name="concurrent" value= "false"></property>
	  </bean>
<bean	id="autoSendMailAndShortMsgTaskTrigger"	class= "org.springframework.scheduling.quartz.CronTriggerFactoryBean" >
	<property name="jobDetail" ref= "autoSendMailAndShortMsgTask"></property>
	<property name="cronExpression" >
	<value>0 0/10 * * * ?</value><!--表示每10分钟运行一次  ,  每位代表的意义:  秒 分 时 周 月 年,  *号表示任意。 -->
	  </property>
	  </bean>
	  <!-- 启动定时器 -->
	 <bean class= "org.springframework.scheduling.quartz.SchedulerFactoryBean" >
		  <property name="triggers" >
			  <list>
				  <ref bean="autoSendMailAndShortMsgTaskTrigger" />
			  </list>
		  </property>
	  </bean>
</beans>

3、类chinatelecom.feildata.web.dataAudit.quartz.AuditWarningQuartz

package chinatelecom.feildata.web.dataAudit.quartz;
public class AuditWarningQuartz {
	public void autoSendMailAndShortMsg(){
		/**
		 * 业务代码
		 */
    }
}

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值