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("定时任务");
        }
    }
  • 相关阅读:
    Eclipse上改动Jython代码的Comment颜色
    StaggeredGridView+universal-image-loader载入网路图片实现瀑布流
    HDU 1890 Robotic Sort
    overload和override
    FileStream大文件复制
    [Asp.Net]状态管理(Session、Application、Cache)
    c#简单自定义异常处理日志辅助类
    Socket网络编程(3)--两端通信
    [Asp.Net]状态管理(ViewState、Cookie)
    Socket网络编程(2)--服务端实现
  • 原文地址:https://www.cnblogs.com/wangfeixiong/p/7072125.html
Copyright © 2011-2022 走看看