定时器quartz配置文件
定时器一般大家都会用到,第一次接触的时候会感觉很高大上,熟悉后觉得挺简单实用,废话不多说直接上配置代码
<?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" xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<!-- 每个定义的任务都要在这里进行引用才能运行 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="buildZXTaskTrigger" />
</list>
</property>
</bean>
<bean id="autoTransferZ" class="com.P2P.base.spring.quartz.TransferZ" />
<!-- 任务调度 -->
<bean id="buildZXTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="autoTransferZX"></property><!-- 关联的bean -->
<property name="targetMethod" value="run"></property><!-- 执行的方法 -->
<property name="concurrent" value="false"/>
</bean>
<!-- 每周六凌晨0230 -->
<bean id="buildZXTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="buildZXTask" />
<property name="cronExpression" value="0 30 2 ? * SAT" />
</bean>
</beans>
<!-- 20170921 -->
<property name="cronExpression" value="0 11 10 23 9 ? 2017" /> <!-- 设置 2017 9/21 17:50:00 执行一次 -->
<!-- 凌晨3:30点 执行-->
<property name="cronExpression" value="0 30 3 * * ?" />
<!--每天凌晨一点执行 -->
<property name="cronExpression" value="0 0 1 * * ?" />
<!--每3分钟 执行-->
<property name="cronExpression" value="0 0/3 * * * ?" /><!-- 0 0/1 * * * ? -->
<!--每15分钟 执行-->
<property name="cronExpression" value="0 0/15 * * * ?" />
配置方法都挺简单的注意要对应好,我自己认为最需要注意的是配置的时间问题,代码里面例举了几种,其他的博客也都有写这里就不赘述了。

浙公网安备 33010602011771号