1,配置文件与spring整合,需要在spring 的总配置中一入或者在web.xml中spring监听中加上
spring-task.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"
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">
<!-- spring自动任务调度器配置 -->
<!-- 要调用的工作类 -->
<bean id="marketSyncAppOrderReqService" class="com.mogu.service.marketSyncAppOrderReqService"></bean>
<!--任务配置列表-->
<bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!--调用的类->
<ref bean="marketSyncAppOrderReqService"/>
</property>
<!--调用类中的方法-->
<value>sendSyncEmail</value>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<ref bean="jobtask"/>
</property>
<!--cron表达式-->
<value>0 0/30 * * * ? *</value>
</property>
</bean>
<bean id="jobtask1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!--调用的类->
<property name="targetObject">
<ref bean="syncRuitongService"/></property>
<!--调用类中的方法->
<value>sync</value>
</property>
</bean>
<!--触发器配置,时间指定-->
<property name="jobDetail">
<ref bean="jobtask1"/>
</property>
<!--cron表达式-->
<property name="cronExpression">
<!-- 每天每隔5分钟执行一次 <value>0 0/5 * * * ?</value> -->
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<property name="triggers">
<!-- 触发器列表 -->
<ref bean="cronTrigger"/>
<ref bean="cronTrigger1"/>
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.threadPool.threadCount">1</prop>
<prop key="org.quartz.threadPool.threadPriority">2</prop>
</props>
</property>
</bean>
</beans>