引用的jar文件
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-logging.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jta.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/log4j-1.2.14.jar.zip"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/quartz-all-1.6.0.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/spring-2.0.6.jar"/>
<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-collections-3.2.jar"/>
web.xml的配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext*.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
resource源输出路径下,applicationContext.xml文件配置:
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="doTest"/>
</list>
</property>
</bean>
applicationContextTest.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:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
<!-- 要调用的工作类 -->
<bean id="actureJob" class="web.ActureJob"></bean>
<!-- 定义调用对象和调用对象的方法 -->
<bean id="jobTest" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="actureJob"/>
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>execute</value>
</property>
</bean>
<bean id="doTest" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobTest"/>
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<!-- 每隔10秒执行一次-->
<value>0/5 * * * * ?</value>
</property>
</bean>
</beans>
实际的业务逻辑定时处理类:
package web;
public class ActureJob {
public void execute(){
System.out.println("my self job!!!");
}
}