025-quartz之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:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:soap="http://cxf.apache.org/bindings/soap"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context.xsd
                        http://www.springframework.org/schema/aop
                        http://www.springframework.org/schema/aop/spring-aop.xsd
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx.xsd
                        http://cxf.apache.org/bindings/soap 
                        http://cxf.apache.org/schemas/configuration/soap.xsd
                        http://cxf.apache.org/jaxws 
                        http://cxf.apache.org/schemas/jaxws.xsd
                        ">
    <!-- quartz配置-1  注册自定义作业类 -->
    <bean name="myJob" class="com.test.quartz.helloworld.MyJob"></bean>
    
    <!-- quartz配置-2  配置JobDetail -->
    <bean name="myJobDetail" 
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 注入目标对象 -->
        <property name="targetObject" ref="myJob"></property>
        <!-- 注入目标方法 -->
        <property name="targetMethod" value="run"></property>
    </bean>
    
    <!--quartz配置-3 配置触发器Trigger -->
    <bean name="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
        <!-- 注入任务详情对象 -->
        <property name="jobDetail" ref="myJobDetail"></property>
        <!-- 注入cron表达式,通过这个表达式指定触发的时间点 -->
        <property name="cronExpression">
            <!-- 每五秒钟触发一次 -->
            <value>0/5 * * * * ?</value>
        </property>
    </bean>
    <!--quartz配置-4  配置scheduler调度工厂-->
    <bean name="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <!-- 注入触发器 -->
        <property name="triggers">
            <list>
                <ref bean="myTrigger"/>
            </list>
        </property>
    </bean>
</beans>

 

posted @ 2018-05-07 12:17  Jepson6669  阅读(185)  评论(0编辑  收藏  举报