在网上找spring+quartz的配置文档都是针对spring2.0版本的,用2.5会莫名其妙的出错,2.5版本的配置如下:
applicationContext-scheduler.xml:
quartz.properties:
TestCheck:
QuartzTest:
applicationContext-scheduler.xml:
<!-- 定时任务 -->
<bean id="schedulerFactoryBean" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doTime"/>
</list>
</property>
<property name="configLocation" value="classpath:quartz.properties"/>
</bean>
<!-- 定义触发时间 -->
<bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="a"/>
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<value>0/5 * * * * ?</value>
</property>
</bean>
<!-- 指定时间工作的类 -->
<bean id="a" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.eway.payweb.scheduler.TestCheck</value>
</property>
</bean>
quartz.properties:
org.quartz.scheduler.instanceName = Sched1
org.quartz.scheduler.instanceId = 1
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
TestCheck:
public class TestCheck extends QuartzJobBean{
public TestCheck(){
}
@Override
public void executeInternal(JobExecutionContext context)
throws JobExecutionException {
JobDetail job= context.getJobDetail();
System.out.println(new Date()+":"+job.getName());
}
}
QuartzTest:
public class QuartzTest {
// @Override
// protected String[] getConfigLocations() {
// return new String[] { "classpath:/applicationContext.xml", "classpath:/applicationContext-scheduler.xml" };
// }
public static void main(String [] argo){
System.out.println("Test start.");
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-scheduler.xml");
System.out.print("Test end..");
}
}