spring-quartz配置

<?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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-4.2.xsd 
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
           http://www.springframework.org/schema/fex         
          http://www.springframework.org/schema/fex/spring-fex.xsd 
           http://www.springframework.org/schema/task          
          http://www.springframework.org/schema/task/spring-task.xsd" >
    
    <!-- 将定时任务相关的类注入到Spring IOC中 -->
    <context:component-scan base-package="com.bshinfo.web" use-default-filters="false">
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Component" />
    </context:component-scan>
    
    <!-- 1.Spring Task 自身的定时任务,由于是硬编码格式,所以不推荐使用 -->
    
    <!-- Enables the Spring Task @Scheduled programming model(Spring quartz定时任务) -->
    <!-- 自动调度需要扫描的包   这种是Spring Task自身的定时任务   需要在定时类加 @Compontent 注解,方法钱加上 @Scheduled(cron = "0/5 * * * * ?")  即可执行-->  
    <!-- 
    <task:executor  id="executor"   pool-size="1" />    
    <task:scheduler id="scheduler"  pool-size="1" />    
    <task:annotation-driven executor="executor" scheduler="scheduler" />
    -->
    
    <!-- 2.Spring Quartz 石英定时,采用可配置方式实现 便于维护 (目前采用)-->
    
    <!-- 1) 指定定时的类和方法 -->
    <bean id="cronTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="QuartzTimerTask" />
        <property name="targetMethod" value="doTest1" />
        <!-- false表示job不会并发执行,默认为true-->
        <property name="concurrent" value="false" />
    </bean>
    
    <!-- 2) 配置触发器 -->
    <bean id="trigger4Test" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <property name="jobDetail" ref="cronTask" />
           <!-- 每30秒执行一次 -->
        <property name="cronExpression" value="0/30 * * * * ?" />
    </bean>
    
    <!-- 3) 配置调度工厂 -->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="trigger4Test" />
            </list>
        </property>
    </bean>
    
    
</beans>

 

posted on 2017-03-14 15:29  老邱2  阅读(114)  评论(0编辑  收藏  举报

导航