zoukankan      html  css  js  c++  java
  • Spring 定时任务的配置

    1.applicationContext.xml 中 加入task 的声明与xsd

    1
    xmlns:task="http://www.springframework.org/schema/task"
    1
    http://www.springframework.org/schema/task  http://www.springframework.org/schema/task/spring-task-4.0.xsd

    配置中加入

    1
    <task:annotation-driven/>

    这个是用来启用自动的注解解析。

    2.编写POJO

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    @Component 
    public class DailyPiracyJob {   
        @Scheduled(cron = "0 0 23 * * ?")
        public void print() throws Exception {
        system.out.println(干点你想干的事!);      
        }
    }

      @Compont 注解,是让Spring context 可以扫描到,并自动注入需要的bean

          @Scheudle 核心注解,不能有返回值,cron是定义了任务运行的间隔,具体,请参考网上其他教程

    需要注意的是,在applicationContext.xml中不能启用 default-lazy-init=“true”,否则注解会失效

  • 相关阅读:
    【2021-04-15】台上一分钟,背后十年功
    【2021-04-14】买了人生中的第一个车位
    计算机网络实验部分
    乘积最大子数组
    计算各个位数不同的数字个数
    周总结
    最长回文子序列
    最长回文串
    回文子串
    拼图
  • 原文地址:https://www.cnblogs.com/jianwei-dai/p/5741482.html
Copyright © 2011-2022 走看看