Spring结合Quartz配置

来源:互联网 发布:金山毒霸网络卸载密码 编辑:程序博客网 时间:2024/05/08 04:23
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"   xmlns:context="http://www.springframework.org/schema/context"   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.5.xsd           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">    <!-- 要调用的工作类 -->     <bean id="reportJob" class="com.all58.video.quartz.ReportJob"></bean>    <bean id="userStatusJob" class="com.all58.video.quartz.UserStatusJob"></bean>    <bean id="inspectPlanJob" class="com.all58.video.quartz.InspectPlanJob"></bean>    <!-- 可继续加新的任务   -->     <!-- 要调用的工作类结束 -->          <!-- 定义调用对象和调用对象的方法 -->    <bean id="reportJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        <!-- 调用的类 -->        <property name="targetObject">            <ref bean="reportJob"/>        </property>        <!-- 调用类中的方法 -->        <property name="targetMethod">            <value>work</value>        </property>     </bean>          <bean id="userStatusJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        <!-- 调用的类 -->        <property name="targetObject">            <ref bean="userStatusJob"/>        </property>        <!-- 调用类中的方法 -->        <property name="targetMethod">            <value>work</value>        </property>     </bean>          <bean id="inspectPlanJobTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">        <!-- 调用的类 -->        <property name="targetObject">            <ref bean="inspectPlanJob"/>        </property>        <!-- 调用类中的方法 -->        <property name="targetMethod">            <value>work</value>        </property>     </bean>                    <!-- 定义触发时间 -->     <bean id="reportJobDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean">         <property name="jobDetail">             <ref bean="reportJobTask"/>         </property>         <!-- cron表达式,每30分钟 执行一次 -->         <property name="cronExpression">             <value>0 0/30 * ? * * </value>         </property>     </bean>           <bean id="userStatusJobDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean">         <property name="jobDetail">             <ref bean="userStatusJobTask"/>         </property>         <!-- cron表达式,每天凌晨1分钟 执行一次 -->         <property name="cronExpression">             <value>0 1 0 * * ?  </value>         </property>     </bean>          <bean id="inspectPlanJobTaskDoTime" class="org.springframework.scheduling.quartz.CronTriggerBean">         <property name="jobDetail">             <ref bean="inspectPlanJobTask"/>         </property>         <property name="cronExpression">             <value>0 0/59 * ? * *</value>         </property>     </bean>               <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序  -->     <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">         <property name="triggers">             <list>                 <ref bean="reportJobDoTime"/>                 <ref bean="userStatusJobDoTime"/>                 <ref bean="inspectPlanJobTaskDoTime"/>             </list>         </property>     </bean></beans>


原创粉丝点击