sping时间触发器

而在Spring里很好的集成了Quartz,在xml文件里面配一下时间就可以自动执行,不需要写一行代码。  

Xml代码  收藏代码
  1. <bean id="methodInvokingJobDetail"      class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">  
  2.        <property name="targetObject"><ref bean="financeDAO"/></property>  
  3.        <property name="targetMethod"><value>confirmOrder</value></property>  
  4.    </bean>    <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">  
  5.        <property name="jobDetail">  
  6.            <ref bean="methodInvokingJobDetail"/>  
  7.        </property>  
  8.        <property name="cronExpression">  
  9.            <value>0 0 6,12,20 * * ?</value>  
  10.        </property>  
  11.    </bean>    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
  12.        <property name="triggers">  
  13.            <list><ref local="cronTrigger"/></list>  
  14.        </property>  
  15.    </bean>  


其中时间的定义按以下例子模仿 
表达式 

Java代码  收藏代码
  1.         意义  
  2. "0/10 * * * * ?"         每十秒触发  
  3. "0 0/1 * * * ?"           每一分钟触发  
  4.   
  5. "0 0 12 * * ?"      每天中午12点触发  
  6. "0 15 10 ? * *"         每天上午10:15触发  
  7. "0 15 10 * * ?"         每天上午10:15触发  
  8. "0 15 10 * * ? *"       每天上午10:15触发  
  9. "0 15 10 * * ? 2005"        2005年的每天上午10:15触发  
  10. "0 * 14 * * ?"      在每天下午2点到下午2:59期间的每1分钟触发  
  11. "0 0/5 14 * * ?"        在每天下午2点到下午2:55期间的每5分钟触发  
  12. "0 0/5 14,18 * * ?"         在每天下午2点到2:55期间和下午6点到6:55期间的每5分钟触发  
  13. "0 0-5 14 * * ?"        在每天下午2点到下午2:05期间的每1分钟触发  
  14. "0 10,44 14 ? 3 WED"        每年三月的星期三的下午2:102:44触发  
  15. "0 15 10 ? * MON-FRI"       周一至周五的上午10:15触发  
  16. "0 15 10 15 * ?"        每月15日上午10:15触发  
  17. "0 15 10 L * ?"         每月最后一日的上午10:15触发  
  18. "0 15 10 ? * 6L"        每月的最后一个星期五上午10:15触发   
  19. "0 15 10 ? * 6L 2002-2005"      2002年至2005年的每月的最后一个星期五上午10:15触发  
  20. "0 15 10 ? * 6#3"       每月的第三个星期五上午10:15触发  




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

Xml代码  收藏代码
  1. default-autowire=byName  


改为 

Xml代码  收藏代码
  1. default-autowire="byName"  


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

Xml代码  收藏代码
    1. <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="no" >  
原文地址:https://www.cnblogs.com/l3985/p/3449953.html