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(){
/**
* 业务代码
*/
}
}