Spring 3整合Quartz 2实现定时任务二:动态添加任务 [url]http://www.dexcoder.com/selfly/article/308[/url]
[color=red]Spring 3整合Quartz 2实现定时任务三[/color]:动态暂停 恢复 修改和删除任务 [url]http://www.dexcoder.com/selfly/article/311[/url]
Quartz的cron表达式 [url]http://www.blogjava.net/javagrass/archive/2011/07/12/354134.html[/url]
Spring Quartz 1.8x [url]http://panyongzheng.iteye.com/blog/2081469[/url]
注:Spring3.2.4配置文件中使用CronTriggerFactoryBean来集成quartz2.x,使用CronTriggerBean来集成quartz1.8.x及以前版本.
这个方法可能避免使用sessionValidationScheduler, 就是避免使用, 就能使用高版本的quartz了.
applicationContext.xml:
<?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:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<!-- 启动触发器的配置开始 -->
<bean name="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="myJobTrigger" />
</list>
</property>
</bean>
<!-- quartz-2.x的配置 -->
<bean id="myJobTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<ref bean="myJobDetail" />
</property>
<property name="cronExpression">
<value>0/1 * * * * ?</value>
</property>
</bean>
<!-- 调度的配置结束 -->
<!-- job的配置开始 -->
<bean id="myJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="myJob" />
</property>
<property name="targetMethod">
<value>work</value>
</property>
</bean>
<!-- job的配置结束 -->
<!-- 工作的bean -->
<bean id="myJob" class="com.pandy.framework.base.comm.quartz.QuartzJob1" />
<!-- 使用注解的方式来扫描定时任务 -->
<!-- 定时器开关 开始-->
<task:annotation-driven/>
<!-- 定时器开关 结束-->
<task:scheduled-tasks>
<task:scheduled ref="quartzJob3" method="work" cron="1/4 * * * * ?"/>
</task:scheduled-tasks>
</beans>
package com.pandy.framework.base.comm.quartz;
/**
* 项目名称: wp_idea_linux
* 功能说明:
* 创建者: Pandy,
* 版权:
* 官网:
* 创建日期: 15-12-3.
* 创建时间: 上午11:46.
* 修改历史:
* -----------------------------------------------
*/
public class QuartzJob1 {
public void work() {
System.out.println("任务调度------------------------------QuartzJob1");
}
}
package com.pandy.framework.base.comm.quartz;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
/**
* 项目名称: wp_idea_linux
* 功能说明:
* 创建者: Pandy,
* 版权:
* 官网:
* 创建日期: 15-12-3.
* 创建时间: 上午11:46.
* 修改历史:
* -----------------------------------------------
*/
@Service
public class QuartzJob2 {
@Scheduled(fixedDelay = 3000)
public void work()
{
System.out.println("任务调度------------------------------QuartzJob2");
}
}
package com.pandy.framework.base.comm.quartz;
import org.springframework.stereotype.Service;
/**
* 项目名称: wp_idea_linux
* 功能说明:
* 创建者: Pandy,
* 版权:
* 官网:
* 创建日期: 15-12-3.
* 创建时间: 上午11:49.
* 修改历史:
* -----------------------------------------------
*/
@Service
public class QuartzJob3 {
public void work()
{
System.out.println("任务调度------------------------------QuartzJob3");
}
}
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Spring config start -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring config end -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>