Quartz依赖
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
</dependency>
spring配置
<?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.xsd">
<bean id="mailJob" class="pdsu.xps.erp.job.MailJob">
<property name="storedetailBiz" ref="storedetailBiz"></property>
</bean>
<bean id="sendStoreAlertMailJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFac
toryBean">
<property name="targetObject" ref="mailJob"></property>
<property name="targetMethod" value="sendStoreAlertMail"></property>
</bean>
<bean id="mailTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="sendStoreAlertMailJobDetail"></property>
<property name="cronExpression" value="0 17 12,16 * * ?"></property>
</bean>
<bean id="startQuartz"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="mailTrigger" />
</list>
</property>
</bean>
</beans>
job工具类
public class MailJob {
private IStoredetailBiz storedetailBiz;
public void setStoredetailBiz(IStoredetailBiz storedetailBiz) {
this.storedetailBiz = storedetailBiz;
}
public void sendStoreAlertMail() {
try {
storedetailBiz.sendStoreAlertMail();
} catch (MessagingException e) {
e.printStackTrace();
}
}
}