1、添加spring依赖jar文件:
见Spring工程的过程:先建一个java工程--->然后点住这个工程,点开Myecplise选项--->里面有个Project Capabilities选项,选其中的Add Spring Capabilities选项,并且选
Spring2.5--->Next--->把Enable AOP Builder的沟去掉并且选择New选项(自己新建一个applicationContext.xml配置文件)--->然后点Finish
2、配置spring加载
监听器:
在web.xml里面配置
<listener>
<listener-
class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
3、在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-2.5.xsd">
<bean name="conversionData" id="conversionData" class="com.plane.timer.ConversionDataJob"></bean>
<bean id="methodInvokingJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="conversionData" />
</property>
<property name="targetMethod">
<value>execute</value>
</property>
</bean>
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="methodInvokingJobDetail" />
</property>
<property name="cronExpression">
<value>0/10 * * * * ?</value>
</property>
</bean>
<bean
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="cronTrigger" />
</list>
</property>
</bean>
</beans>
当然,在上面的配置信息里也可以添加多个定时器