zoukankan      html  css  js  c++  java
  • spring定时任务

    spring定时任务有两种实现方式:

    1、注解方式

    2、XML配置

    在具体实现之前,我们需要在spring配置中引入一些东西:

    xmlns 中的 xmlns:task="http://www.springframework.org/schema/task"

    xsi 中的 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">

    引入job包:<context:component-scan base-package="job" /> 

    具体配置如下:

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">


    <!-- 配置定时任务 -->
    <!-- <task:scheduled-tasks>
    <task:scheduled ref="TestScheduledJob" method="handleTask" cron="0/5 * * * * ?"/>
    </task:scheduled-tasks> -->


    <context:component-scan base-package="job" />

    <task:annotation-driven/>
    </beans>

    1、注解方式(每五秒执行一次)

    2、XML配置方式

  • 相关阅读:
    【Java学习笔记】I/O体系
    【Java学习笔记】几个实用类
    【Java学习笔记】内部类
    【Java学习笔记】对象的序列化和反序列化
    【Java学习笔记】数组的相关事项
    【Java学习笔记】由String str=”abc”引出的故事
    【Java学习笔记】上转型与下转型
    【Java学习笔记】枚举类型
    【Java学习笔记】集合类
    Maven的settings.xml中为HTTP和HTTPS配置代理服务器【转】
  • 原文地址:https://www.cnblogs.com/chun-chun/p/9563097.html
Copyright © 2011-2022 走看看