环境:
1 Spring3.05
2 quartz 1.8.6 (由于Spring3.05与quartz 2.0不兼容,所以,还是选用quartz 1.8.6)
3 eclipse 3.7
4 tomcat 7
5 jdk6
代码:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>LeoWeb</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app> |
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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean name="helloWorldService" class="com.leoweb.service.impl.HelloWorldImpl"></bean> <bean name="helloWorldJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <property name="targetObject" ref="helloWorldService" /> <property name="targetMethod" value="sayHello" /> <property name="concurrent" value="false" /> </bean> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="helloWorldJob" /> <property name="cronExpression" value="0/10 * * * * ?" /> </bean> <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="cronTrigger" /> </list> </property> </bean> </beans> |
HelloWorld.java
package com.leoweb.service; public interface HelloWolrd { |
HelloWorldImpl.java
package com.leoweb.service.impl; import com.leoweb.service.HelloWolrd; public class HelloWorldImpl implements HelloWolrd { @Override } |
参考资料:
1 《Spring 2.0核心技术与最佳实践》,廖雪峰,电子工业出版社,2007年6月
2 《Spring Reference Documentation 3.0》
4 http://topic.youkuaiyun.com/u/20120327/23/847ba00d-b7bc-48ec-aa0a-5a153194b392.html