Spring Quartz 任务调度配置一

1、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"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
    default-autowire="byName" default-lazy-init="true"> 


   <bean id="testQuartz" class="spring.quartz.test.TestQuartz" lazy-init="false"/>  
   
   <!--定义定时执行testQuartz这个bean中的test()方法 -->
   <bean id="task"
              class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject">
              <ref bean="testQuartz" />
        </property>
        <property name="targetMethod">
            <value>test</value>
        </property>
        <property name="concurrent" value="false"/>
 </bean>
 
 <!--
  触发器的bean的设置,在这里我们设置了我们要触发的jobDetail是哪个。这里我们定义了要触发的jobDetail是task,即触发器去触发哪个bean..并且我们还定义了触发的时间
 -->
 <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
      <property name="jobDetail">
          <ref bean="task" />
      </property>
      <property name="cronExpression">  
           <value>1-59 * * * * ?</value>                       
      </property>
 </bean>  
    <!--
     管理触发器的总设置,管理我们的触发器列表,可以在bean的list中放置多个触发器。   
    -->
 <bean id="schedulerFactory" lazy-init="false" autowire="no"   

            class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
     <property name="triggers">
           <list>
               <ref local="cronTrigger" />
           </list>
     </property>
 </bean>
 
</beans> 

2、testQuartz代码

public class TestQuartz {

     public void test() {
         System.out.println("任务执行中....................................!");
    }

}

猜你喜欢

转载自ligure.iteye.com/blog/1039070