一直都用CronTriggerBean,都还不知道有SimpleTriggerBean,
失败!
做个记录
转自:http://blog.163.com/jianlizhao@126/blog/static/1732511632011124112234761/s
Spring对Quartz调度的支持
Spring对Quartz集成与其对JDK Timer调度集成类似,你可以在配置文件中配置任务调度。仅需要在程序里加载ApplicationContext,Spring会自动启动调度器。
quartz.xml
Java代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 定义调用对象和调用对象的方法 -->
<bean id="job"
class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value> com.learnworld.quartz.MessageJob </value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="message">
<value>This is a message from Spring Quartz configuration!</value>
</entry>
</map>
</property>
</bean>
<!-- 定义触发时间 -->
<bean id="trigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="startDelay">
<value>1000</value>
</property>
<property name="repeatInterval">
<value>3000</value>
</property>
<property name="jobDetail">
<ref local="job" />
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="schdulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="trigger" />
</list>
</property>
</bean>
</beans>
SimpleSpringQuartzIntegration.java
Java代码
package com.learnworld.quartz;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class SimpleSpringQuartzIntegration {
public static void main(String[] args) {
ApplicationContext ac = new FileSystemXmlApplicationContext("src/conf/quartz.xml");
}
}