Spring quartz定时任务无法触发
今天用Spring的定时任务做了一个例子,但是始终无法触发,请大家帮忙:
1. applicationContext配置:test_spring.xml
<!-- 普通的业务Bean -->
<bean name="testService" class="test.quartzTest"/>
<!-- 作业 -->
<bean id="jobDetail_test" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="testService"/>
<property name="targetMethod" value="SayHello"/>
</bean>
<!-- 触发器 -->
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobDetail_test"/>
</property>
<!-- 10点开始没5秒运行一次 -->
<property name="cronExpression">
<value>0/5 * 10 * * ?</value>
</property>
</bean>
<!-- 计划 -->
<bean id = "testScheduler" lazy-init = "true" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
</list>
</property>
</bean>
2. 业务类
package test;
public class quartzTest {
public void SayHello() {
// TODO Auto-generated method stub
System.exit(1);
try {
System.out.println("处理任务开始>........");
// 业务逻辑代码调用
System.out.println("时间[" + new java.util.Date().toLocaleString()
+ "]----->大家好啊!");
System.out.println("处理任务结束!");
} catch (Exception e) {
e.printStackTrace();
}
}
public void hello(){
System.out.println("test");
}
}
3.测试类
package test;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
public class test {
public static void main(String[] args) throws IOException {
ApplicationContext ac = new ClassPathXmlApplicationContext("test_spring.xml");
System.out.println("test");
SchedulerFactoryBean test = (SchedulerFactoryBean) ac.getBean("testScheduler");
}
}
以上就是所有的代码了,在eclipes中运行,一直未成功啊,请各位大大帮忙!!!