热门标签 | HotTags
当前位置:  开发笔记 > Android > 正文

springtask定时任务实现示例

一、引入spring相关jar包: 二、在web.xml中配置spring Spring监听器 org.spr

一、引入spring相关jar包:

二、在web.xml中配置spring


  Spring监听器
  org.springframework.web.context.ContextLoaderListener


  contextConfigLocation
  classpath:applicationContext.xml

三、在applicationContext.xml中配置监听器

<&#63;xml version="1.0" encoding="UTF-8"&#63;>


  
  
  
  
  
  
  



四、编写实体类

package com.test.task;

import java.text.DateFormat;
import java.util.Date;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class TestTask {
  @Scheduled(cron = "*/5 * * * * &#63;")
  public void print(){
    String time = DateFormat.getDateTimeInstance().format(new Date());
    System.out.println("定时器触发打印"+time);
  }
}

五、工程目录:

运行结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。


推荐阅读
author-avatar
浅笑你的妩媚
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有