首页 > 代码库 > [原创] 在spring 中使用quarts

[原创] 在spring 中使用quarts

 

 

1.使用maven加载 quarts 的jar

1 <dependency>2             <groupId>org.quartz-scheduler</groupId>3             <artifactId>quartz</artifactId>4             <version>1.8.0</version>5  </dependency>

 

2.spring 中配置 bean

 

 

 1 <!-- schedule all jobs for quartz--> 2 <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 3     <property name="triggers"> 4         <list> 5            <ref local="dataScanTrigger1" />    6            <ref local="dataScanTrigger2" />  7         </list> 8     </property> 9 </bean> 10 //定义触发器11 <bean id="dataScanTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">12   <property name="jobDetail">13       <ref bean="scanJobDetail1" />14   </property>15   <property name="cronExpression">16       <value>0 */1 * * * ?</value>//触发器执行的时间17   </property>18 </bean>
//定义具体的实现类 实现方法
19 <bean id="scanJobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">20 <property name="targetObject"> 21 <ref bean="dataScan" />22 </property>23 <property name="targetMethod"> 24 <value>scanShopsInfo</value>25 </property>26 <property name="concurrent"> 27 <value>false</value>28 </property>29 </bean>30 31 32 <bean id="dataScanTrigger2" class="org.springframework.scheduling.quartz.CronTriggerBean">33 <property name="jobDetail">34 <ref bean="scanJobDetail2" />35 </property>36 <property name="cronExpression">37 <value>0 50 23 * * ?</value>38 </property>39 </bean>40 <bean id="scanJobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">41 <property name="targetObject"> 42 <ref bean="dataScan" />43 </property>44 <property name="targetMethod"> 45 <value>scanOrder</value>46 </property>47 <property name="concurrent"> 48 <value>false</value>49 </property>50 </bean>

 

DataScan.java

 1 public class DataScan { 2  3   /** 4      *  5      * @author:jason_zhangz@163.com 6      * @time:2016-8-26下午4:50:35 7      * @des:扫描 8      */ 9     public void scanOrder(){10         11         //对beautyShop 进行空查询,获取所有的 shopId ,shopName12         List<BeautyShop> shops = beautyShopOperator.getAllBeautyShopInaCity(null);13         orderOperator.staGetStatisticOrders(shops);14         15     }16     17 ......18 19 20 }

 

[原创] 在spring 中使用quarts