zoukankan      html  css  js  c++  java
  • spring-task解决定时问题

     spring3以上版本,spring-content自带 spring-task ,来解决工程中的定时问题

     基于注解配置spring定时任务

    spring配置文件如下:

    <?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:context="http://www.springframework.org/schema/context"
        xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
        xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd ">
    
        <mvc:annotation-driven />
    
        <context:component-scan base-package="com" />
        
         <!--开启该组件就可以,基于注解使用定时任务啦 -->
        <task:annotation-driven />
    
    </beans>

    java代码中的书写规范:

    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Service;
    
    @Service
    public class Demo
    {
        @Scheduled(cron = "*/5 * * * * ?") 
        public void tast()
        {
            System.out.println("定时任务");
        }
    }
  • 相关阅读:
    'jar' 不是内部或外部命令,也不是可运行的程序 或批处理文件。或批处理文件
    idea 集成 javap
    JVM_ 动态链接
    远程服务调用RMI框架 演示,和底层原理解析
    IO/NIO/AIO 解读
    JUC 并发编程--10, 阻塞队列之--LinkedBlockingDeque 工作窃取, 代码演示
    github,使用技巧, 让你的开发事半功倍
    JVM-相关,这里引用别人博客
    python开发学习day01 (编程; 计算机三大核心硬件 ; 操作系统与平台)
    webdriervAPI(多表单切换)
  • 原文地址:https://www.cnblogs.com/wangfeixiong/p/7072125.html
Copyright © 2011-2022 走看看