Spring Quartz 任务调度配置二
1、Spring 配置文件模板
?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
??? xmlns:aop="http://www.springframework.org/schema/aop"
??? xmlns:tx="http://www.springframework.org/schema/tx"
??? xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
?????????? http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
?????????? http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
??? default-autowire="byName" default-lazy-init="true">?
?<bean id="service" lazy-init="false"/>??
?
<!-- 要调度的对象?? 索引的服务-->
<bean id="task" value="spring.quartz.test.TestQuartz"/>
??<property name="jobDataAsMap">
??????<map>
???????? ?<entry key="service">
??????? ????? <ref bean="service" />
??????? ? </entry>
??????</map>
???</property>
</bean>
?
?<!--
??触发器的bean的设置,在这里我们设置了我们要触发的jobDetail是哪个。这里我们定义了要触发的jobDetail是task,即触发器去触发哪个bean..并且我们还定义了触发的时间
?-->
?<bean id="cronTrigger" />
????? </property>
????? <property name="cronExpression">??
?????????? <value>1-59 * * * * ?</value>???????????????????????
??????</property>
?</bean>??
??? <!--
??? ?管理触发器的总设置,管理我们的触发器列表,可以在bean的list中放置多个触发器。???
??? -->
?<bean id="schedulerFactory" lazy-init="false" autowire="no"???
??????????? />
?????????? </list>
?????</property>
?</bean>
?
</beans>?
?
2、testQuartz Bean 代码
public class TestQuartz extends QuartzJobBean {
????private Service service;
??? @Override
??? protected void executeInternal(JobExecutionContext arg0)
????throws JobExecutionException {
??????? service.test();
??? }
??? public Service getService() {
?????? ?return service;
??? }
?? ?public void setService(Service service) {
??????? this.service = service;
??? }
}
?
3、Service Bean 代码
public class Service {
??? public void test(){
??????? System.out.println("任务执行中.....................");
?? ?}
}
?
?