quartz 時間排程器 配置檔案
阿新 • • 發佈:2019-01-27
廢話不多說直接上配置檔案
<?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:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:aop="http://www.springframework.org/schema/aop"
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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"
default-lazy-init="false">
<!-- 配置需要定時的bean類 -->
<bean id="festivalRemindTask" class="com.cl.business.khkq.util.festivalRemindTask"></bean>
<!-- 工程交付週期表 -->
<bean id="periodChartTask" class="com.cl.business.pcdm.util.PeriodChartTask"></bean>
<!-- 配置任務的具體類和方法 -->
<bean id="startWorkTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 要呼叫的bean -->
<property name="targetObject" ref="festivalRemindTask"></property>
<!-- 要呼叫的Method -->
<property name="targetMethod" value="festivalRemind"></property>
<!-- <property name="targetMethod" value="nsTime"></property> <property
name="targetMethod" value="nsWarnTime"></property> <property name="targetMethod"
value="validDate"></property> -->
<!-- <property name="targetMethod"> <value>festivalRemind</value> <value>nsTime</value>
<value>nsWarnTime</value> <value>validDate</value> </property> -->
<!-- 是否併發,false表示 如果發生錯誤也不影響下一次的呼叫 -->
<property name="concurrent" value="false"></property>
</bean>
<bean id="startPeriodChartTask"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 要呼叫的bean -->
<property name="targetObject" ref="periodChartTask"></property>
<!-- 要呼叫的Method -->
<property name="targetMethod" value="runTask"></property>
<!-- 是否併發,false表示 如果發生錯誤也不影響下一次的呼叫 -->
<property name="concurrent" value="false"></property>
</bean>
<!-- 配置一個觸發器 -->
<bean id="startWorkTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="startWorkTask"></property>
<!-- 0 0/1 * * * ? 每分鐘執行一次 -->
<property name="cronExpression" value="0 0 10 * * ?"></property> <!--每天的上午十點觸發"0 45 11 * * ?" -->
<!-- <property name="cronExpression" value="0 0/1 * * * ?"></property> --><!--每五分鐘執行一次 -->
</bean>
<!--工程交付週期表觸發器 -->
<bean id="periodChartTaskTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="startPeriodChartTask"></property>
<!-- 0 0/1 * * * ? 每分鐘執行一次 -->
<!-- <property name="cronExpression" value="0 0 10 * * ?"></property> --> <!--每天的上午十點觸發"0 45 11 * * ?" -->
<property name="cronExpression" value="0 0/5 * * * ?"></property> <!--每五分鐘執行一次 -->
</bean>
<!-- 總排程,用於啟動定時器 -->
<bean id="schedulerFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="startWorkTrigger" />
<!-- <ref bean="periodChartTaskTrigger" /> -->
</list>
</property>
</bean>
</beans>