问题描述
请问quartz 2.1.5里怎么通过表达式表达从具体某年某月某天到某年某月某天,例如:我希望从2013-08-14号到2014-07-13号每天的的凌晨1点执行,表达式改怎么写啊?
解决方案
建议用spring的org.springframework.scheduling.quartz.SimpleTriggerBean,下面的例子完美通过,从2013-08-14 11:07:00到2013-08-14 11:09:00,每隔10秒执行一次<bean id="dateEditor" class="org.springframework.beans.propertyeditors.CustomDateEditor"> <constructor-arg> <bean class="java.text.SimpleDateFormat"> <constructor-arg value="yyyy-MM-dd HH:mm:ss" /> </bean> </constructor-arg> <constructor-arg value="true" /> </bean> <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <property name="customEditors"> <map> <entry key="java.util.Date"> <ref local="dateEditor" /> </entry> </map> </property> </bean> <bean id="triggerTest" class="com.chinahrt.zyn.chengdu.TriggerTest"/> <bean id="miJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><property name="targetObject"><ref bean="triggerTest"/></property><property name="targetMethod"><value>init</value></property></bean><bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"><property name="jobDetail"><ref bean="miJobDetail"/></property><property name="startTime"><value>2013-08-14 11:07:00</value></property><property name="endTime"><value>2013-08-14 11:09:00</value></property><property name="repeatInterval"><value>10000</value></property></bean><bean id="sfb" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="triggers"><list><ref local="simpleTrigger"/></list></property></bean>,package com.chinahrt.zyn.chengdu;import java.text.SimpleDateFormat;import java.util.Date;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class TriggerTest {SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");public void init(){System.out.println(sdf.format(new Date()));}public static void main(String[] args){ApplicationContext ctx = new ClassPathXmlApplicationContext(TriggerTest.class.getResource("spring.xml").toString());}},2013-08-14 11:04:59,764 INFO [AbstractApplicationContext.prepareRefresh(411)] - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2a340e: display name [org.springframework.context.support.ClassPathXmlApplicationContext@2a340e]; startup date [Wed Aug 14 11:04:59 CST 2013]; root of context hierarchy2013-08-14 11:04:59,826 INFO [XmlBeanDefinitionReader.loadBeanDefinitions(323)] - Loading XML bean definitions from URL [file:/E:/workspace4/DataUtil/bin/com/chinahrt/zyn/chengdu/spring.xml]2013-08-14 11:05:00,045 INFO [AbstractApplicationContext.obtainFreshBeanFactory(426)] - Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@2a340e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@5e5a502013-08-14 11:05:00,201 INFO [DefaultListableBeanFactory.preInstantiateSingletons(414)] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5e5a50: defining beans [dataSource,jdbcTemplate,dateEditor,org.springframework.beans.factory.config.CustomEditorConfigurer#0,triggerTest,miJobDetail,simpleTrigger,sfb]; root of factory hierarchy2013-08-14 11:05:00,217 INFO [DriverManagerDataSource.setDriverClassName(155)] - Loaded JDBC driver: com.mysql.jdbc.Driver2013-08-14 11:05:00,420 INFO [QuartzScheduler.<init>(195)] - Quartz Scheduler v.1.5.2 created.2013-08-14 11:05:00,420 INFO [RAMJobStore.initialize(138)] - RAMJobStore initialized.2013-08-14 11:05:00,420 INFO [StdSchedulerFactory.instantiate(1014)] - Quartz scheduler 'sfb' initialized from an externally provided properties instance.2013-08-14 11:05:00,420 INFO [StdSchedulerFactory.instantiate(1018)] - Quartz scheduler version: 1.5.22013-08-14 11:05:00,420 INFO [QuartzScheduler.setJobFactory(1853)] - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@29ab3e2013-08-14 11:05:00,436 INFO [SchedulerFactoryBean.startScheduler(626)] - Starting Quartz Scheduler now2013-08-14 11:05:00,436 INFO [QuartzScheduler.start(400)] - Scheduler sfb_$_NON_CLUSTERED started.2013-08-14 11:07:002013-08-14 11:07:102013-08-14 11:07:202013-08-14 11:07:302013-08-14 11:07:402013-08-14 11:07:502013-08-14 11:08:002013-08-14 11:08:102013-08-14 11:08:202013-08-14 11:08:302013-08-14 11:08:402013-08-14 11:08:50
解决方案二:
0 0 1 14-13 8-7 ? 2013-2014