• 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配置方式

  • 相关阅读:
    【计算机网络】网络地址转换NAT
    红黑树
    引用和取地址区别
    [网络编程] TCP、UDP区别以及TCP传输原理、拥塞避免、连接建立、连接释放总结
    操作系统大端模式和小端模式
    点乘和叉乘
    HMM模型
    Application_Start
    跨函数使用内存空间
    框架
  • 原文地址:https://www.cnblogs.com/chun-chun/p/9563097.html
Copyright © 2020-2023  润新知