1.创建一个xml(名字.xml),注意代码中的名字A,名字B,名字C的位置,且和其他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: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.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
//id名字要唯一,不要和其他的定时任务bean重了,class参数写到要运行方法所在的类的名字
<bean id="名字A" class="cn.wiztek.chsms.nhousechange.servlet.NhouseChangeAppServlet">
</bean>
<!-- 配置作业类 -->
<bean id="名字B" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject"> <!-- 指定任务类 -->
<ref bean="名字A"/>
</property>
<property name="targetMethod" value="要运行的方法名" /> <!-- 指定运行的方法 -->
<property name="concurrent" value="false" /> <!-- 作业不并发调度 -->
</bean>
<!-- 配置作业调度的触发方式(触发器) -->
<bean id="名字C" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="名字B" />
<property name="cronExpression" value="0 0 9 * * ?" /> <!-- 每天9点执行一次 -->
</bean>
<!-- 配置调度工厂 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="名字C" />
</list>
</property>
</bean>
</beans>
2.在applicationContext.xml中添加
//引号内容为刚才建的xml的位置,从和applicationContext.xml同级目录位置开始写(新建xml和applicationContext.xml在同一个文件夹中),不在同文件夹情况本人没试过
<import resource="..位置../名字.xml" />
3.重启程序测试即可