Spring时间触发器

而在Spring里很好的集成了Quartz,在xml文件里面配一下时间就可以自动执行,不需要写一行代码。 
 <bean id="methodInvokingJobDetail"      class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject"><ref bean="financeDAO"/></property>
        <property name="targetMethod"><value>confirmOrder</value></property>
    </bean>    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="methodInvokingJobDetail"/>
        </property>
        <property name="cronExpression">
            <value>0 0 6,12,20 * * ?</value>
        </property>
    </bean>    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list><ref local="cronTrigger"/></list>
        </property>
    </bean>

其中时间的定义按以下例子模仿
表达式
	 	意义
"0/10 * * * * ?"         每十秒触发
"0 0/1 * * * ?"           每一分钟触发

"0 0 12 * * ?" 	  	每天中午12点触发
"0 15 10 ? * *" 	  	每天上午10:15触发
"0 15 10 * * ?" 	  	每天上午10:15触发
"0 15 10 * * ? *" 	  	每天上午10:15触发
"0 15 10 * * ? 2005" 	  	2005年的每天上午10:15触发
"0 * 14 * * ?" 	  	在每天下午2点到下午2:59期间的每1分钟触发
"0 0/5 14 * * ?" 	  	在每天下午2点到下午2:55期间的每5分钟触发
"0 0/5 14,18 * * ?" 	  	在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发
"0 0-5 14 * * ?" 	  	在每天下午2点到下午2:05期间的每1分钟触发
"0 10,44 14 ? 3 WED" 	  	每年三月的星期三的下午2:10和2:44触发
"0 15 10 ? * MON-FRI" 	  	周一至周五的上午10:15触发
"0 15 10 15 * ?" 	  	每月15日上午10:15触发
"0 15 10 L * ?" 	  	每月最后一日的上午10:15触发
"0 15 10 ? * 6L" 	  	每月的最后一个星期五上午10:15触发 
"0 15 10 ? * 6L 2002-2005" 	  	2002年至2005年的每月的最后一个星期五上午10:15触发
"0 15 10 ? * 6#3" 	  	每月的第三个星期五上午10:15触发



如果出现了“Table 'database.qrtz_locks' doesn't exist”异常
有两种处理方法
方法1
则处理方法为在声明中的
default-autowire=byName

改为
default-autowire="byName"

方法2
配置文件在<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
多个autowire=no 属性,如下
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="no" > 

猜你喜欢

转载自xixian.iteye.com/blog/1068889