设为首页 加入收藏

TOP

定时任务(一)
2017-10-13 10:35:05 】 浏览:10055
Tags:定时 任务

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>
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java中抽象类和接口的区别 下一篇可变对象与不可变对象

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目