springmvc,mybatis增加quartz

之前springmvc,mybtais整合的文章:http://www.cnblogs.com/acehalo/p/3901809.html

现在新增quartz

quartz配置参考的http://www.oschina.net/question/8676_9032

pom新加依赖:

<!-- quartz -->
<dependency>
   <groupId>org.quartz-scheduler</groupId>
   <artifactId>quartz</artifactId>
   <version>1.8.5</version>
  </dependency>

applicationContext.xml新增bean:

<bean id="testJob" class="com.hi.test.quartz.TestJob"/>  

<bean id="testJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">   
        <property name="targetObject" ref="testJob"/>  
        <property name="targetMethod" value="execute"/>  
        <property name="concurrent" value="false"/>
        <!-- 是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程 -->  
</bean>  

<bean id="testTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">  
       <property name="jobDetail" ref="testJobDetail"/>  
       <property name="cronExpression" value="*/1 * * * * ?"/><!-- 每隔1秒钟触发一次 -->  
</bean> 


    <bean lazy-init="false"  class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
       <property name="triggers">  
           <list>  
              <ref bean="testTrigger"/>  
           </list>  
       </property>  
       <property name="autoStartup" value="true"/>  
</bean>  
com.hi.test.quartz.TestJob类:
package com.hi.test.quartz;

import java.util.Date;

public class TestJob {
      public void execute(){  
            try{  
                  System.out.println(new Date());
             }catch(Exception ex){  
                 ex.printStackTrace();  
             }  
         }  
}

 

posted @ 2014-08-10 13:24  oh~NO!  阅读(1295)  评论(0编辑  收藏  举报