1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 4 xsi:schemaLocation="http://www.springframework.org/schema/beans 5 http://www.springframework.org/schema/beans/spring-beans-4.1.xsd"> 6 7 <!-- 商品權重更新,天天凌晨0點執行一次 --><!-- 指向的是要執行的類 --> 8 <bean id="myJob" class="cc.knms.appservice.trigger.GoodsWeightTrigger" /> 9 10 <bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 11 <property name="targetObject"> 12 <ref bean="myJob" /> 13 </property> 14 <!-- 指向方法,這裏的value是方法名稱 --> 15 <property name="targetMethod"> 16 <value>updateWeight</value> 17 </property> 18 </bean> 19 <bean id="myJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 20 <property name="jobDetail"> 21 <ref bean="myJobDetail" /> 22 </property> 23 <!-- 多久執行,這裏表示天天凌晨執行 --> 24 <property name="cronExpression"> 25 <value>0 0 1 * * ? </value> 26 </property> 27 </bean> 28 29 <!-- 推送,每過5分執行一次 --> 30 <bean id="msgWork" class="cc.knms.appservice.trigger.MsgWork"></bean> 31 <bean id="msgWorkDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 32 <property name="targetObject"> 33 <ref bean="msgWork" /> 34 </property> 35 <property name="targetMethod"> 36 <value>sendMsg</value> 37 </property> 38 </bean> 39 <bean id="msgWorkTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 40 <property name="jobDetail"> 41 <ref bean="msgWorkDetail" /> 42 </property> 43 <property name="cronExpression"> 44 <value>0 0/1 * * * ?</value> 45 </property> 46 </bean> 47 48 <!-- 訂單查詢 每隔5分鐘執行一次 --> 49 <bean id="orderQuery" class="cc.knms.appservice.trigger.OrderQueryTrigger"></bean> 50 <bean id="orderQueryDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 51 <property name="targetObject"> 52 <ref bean="orderQuery" /> 53 </property> 54 <property name="targetMethod"> 55 <value>query</value> 56 </property> 57 </bean> 58 <bean id="orderQueryTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> 59 <property name="jobDetail"> 60 <ref bean="orderQueryDetail" /> 61 </property> 62 <property name="cronExpression"> 63 <!-- 每隔5分鐘執行一次 --> 64 <!--<value>0 44 10 * * ? *</value>--> 65 <value>0 0/5 * * * ?</value> 66 </property> 67 </bean> 68 69 70 71 <!-- 啓動觸發器的配置開始 --> 72 <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 73 <property name="triggers"> 74 <list> 75 <ref bean="msgWorkTrigger" /> 76 <ref bean="myJobTrigger" /> 77 <ref bean="orderQueryTrigger" /> 78 </list> 79 </property> 80 </bean> 81 <!-- 啓動觸發器的配置結束 --> 82 </beans>
下面是第一個定時任務對應的方法
1 public class GoodsWeightTrigger { 2 3 @Autowired 4 private KnGoodsDataService goodsDataServie; 5 6 public void updateWeight(){ 7 goodsDataServie.updateWeight(); 8 } 9 10 }
對應的實現spring
@Service public class KnGoodsDataServiceImpl implements KnGoodsDataService { @Autowired private KnGoodsMapper goodsMapper; @Autowired private KnInspirationMapper InspirationMapper; @Autowired private KnRepairMasterMapper repairmastermapper; @Autowired private KnSellerpreferMapper sellerprefermapper; /** * @autho 李方華 * @remark 天天修改權重值 * @date 2016年10月19日 下午3:41:10 * @param 同一時間 * @return * @throws ParseException */ @Override public synchronized void updateWeight() { int countGoods = goodsMapper.updateWeight(20); if(countGoods>0){ int countInspiration = InspirationMapper.updateWeight(20); if(countInspiration>0){ int countSellerprefer = sellerprefermapper.updateWeight(20); if(countSellerprefer > 0){ repairmastermapper.updateWeight(20); } } } }
這裏寫得比較簡單,但願能有參考價值app