spring配置定时器

来源:互联网 发布:js去掉html a标签 编辑:程序博客网 时间:2024/06/06 16:28
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">


<!-- 启动触发器的配置开始 -->
<bean name="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="myJobTrigger" />
<ref bean="itemDiscountJobTrigger" />
<ref bean="matchProcessJobTrigger" />
</list>
</property>
</bean>
<!-- 启动触发器的配置结束 -->


<!-- quartz-2.x的配置 -->
<bean id="myJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail"><ref bean="myJobDetail" /></property>
<property name="cronExpression"><value>0 15 10 15 * ?</value></property>
</bean>
<!-- 调度的配置结束 -->


<!-- job的配置开始 -->
<!--调度工厂-->
<bean id="myJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="myJob" />
</property>
<property name="targetMethod">
<value>backup</value>
</property>
</bean>
<!-- job的配置结束 -->
 
<!-- 工作的bean -->
<bean id="myJob" class="com.snsoft.base.core.job.BackupForMysql" />

<!-- quartz-2.x的配置 -->
<!-- 
<property name="cronExpression" value="0 00 22 * * ?" />
字段 允许值 允许的特殊字符 
秒 0-59 , - * / 
分 0-59 , - * / 
小时 0-23 , - * / 
日期 1-31 , - * ? / L W C 
月份 1-12 或者 JAN-DEC , - * / 
星期 1-7 或者 SUN-SAT , - * ? / L C # 
年(可选) 留空, 1970-2099 , - * /

1 * * * * ? :代表每天每小时每分钟第1秒触发 
5 * * * * ? :代表每分钟第5秒触发
0 15 * * * ?-在每天每小时15分触发
0 0 12 * * ?-在每天中午12:00触发 
0 15 10 * * ?-每天上午10:15 触发 
0 15 10 * * ? *-每天上午10:15 触发 
0 15 10 * * ? 2005-在2005年中的每天上午10:15 触发 
0 * 14 * * ?-每天在下午2:00至2:59之间每分钟触发一次
 
0/1 * * * * ? :代表每1秒 触发
0/2 * * * * ? :代表每2秒 触发
0 0/1 * * * ? :代表每分钟 触发
0 0 0/1 * * ? :代表每小时 触发
0 0 0 0/1 * ? :代表每天 触发
-->
<bean id="itemDiscountJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail"><ref bean="itemDiscountJobDetail" /></property>
<property name="cronExpression"><value>1 0 * * * ?</value></property>
</bean>
<bean id="itemDiscountJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="dataItemDiscountJob" />
</property>
<property name="targetMethod">
<value>itemDiscount</value>
</property>
</bean>
<!-- 工作的bean -->
<bean id="dataItemDiscountJob" class="com.snsoft.item.controller.DataItemController" />


<bean id="matchProcessJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail"><ref bean="matchProcessJobDetail" /></property>
<property name="cronExpression"><value>1 0 * * * ?</value></property>
</bean>
<bean id="matchProcessJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="matchProcessJob" />
</property>
<property name="targetMethod">
<value>matchProcess</value>
</property>
</bean>
<bean id="matchProcessJob" class="com.snsoft.platform.controller.DataMatchInfoController" />



</beans>
原创粉丝点击