Naims_task.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:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">
<task:annotation-driven /> <!-- 定时器开关-->
<bean id="myTask" class="com.wisoft.jazwfw.convenienceServices.controller.ConvenienceServicesController"></bean>
<task:scheduled-tasks>
<!-- 这里表示的是每天23点59分执行一次 -->
<task:scheduled ref="myTask" method="getPubService" cron="0 59 23 * * ?" />
<!-- 这里表示的是每隔十秒执行一次 -->
<!-- <task:scheduled ref="myTask" method="print" cron="*/10 * * * * ?"/> -->
</task:scheduled-tasks>
<!-- 自动扫描的包名 -->
<context:component-scan base-package="com.wisoft.jazwfw.convenienceServices.controller" />
</beans>
然后在Naims_main.xml引入
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="spring/Naims_ws.xml" />
<import resource="spring/Naims_bo.xml" />
<import resource="spring/Naims_dao.xml"/>
<import resource="spring/Naims_params.xml"/>
<import resource="spring/Naims_task.xml"/>
</beans>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
spring的定时任务配置分为三个步骤:
1、定义任务
2、任务执行策略配置
3、启动任务
1、定义任务
<!--要定时执行的方法-->
<bean id="testTaskJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<!--指定要定时执行的方法所在类,将定时任务定义成bean-->
<ref bean="testTask" />
</property>
<property name="targetMethod">
<!--指定定时执行的方法-->
<value>execute</value>