spring boot:

@EnableScheduling开启计划任务支持,

@Scheduled计划任务声明

 package ch2.scheduler2;

 //日期转换方式
import java.text.SimpleDateFormat;
import java.util.Date; //计划任务声明
import org.springframework.scheduling.annotation.Scheduled;
//spring组件注解
import org.springframework.stereotype.Service; @Service
public class SchedulerService { private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH::mm::ss"); @Scheduled(fixedRate=)
public void proFixCurrentTime()
{
System.out.println("每5秒钟执行一次:" + dateFormat.format(new Date()));
} @Scheduled(cron="0 53 18 ? * *")
public void cornCurrentTime()
{
System.out.println("自定执行时间: " + dateFormat.format(new Date()));
} }
 package ch2.scheduler2;

 //引入spring配置注解
import org.springframework.context.annotation.Configuration;
//引入spring自动载入注解
import org.springframework.context.annotation.ComponentScan; //计划任务声明类:开启计划任务声明
import org.springframework.scheduling.annotation.EnableScheduling; //spring配置类声明
@Configuration
//自动引入当前包下的service,component....
@ComponentScan("ch2.scheduler2")
//开启对计划任务的支持
@EnableScheduling
public class TaskSchedulerConfig { }
 package ch2.scheduler2;
//引入容器
import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Main { public static void main(String[] args)
{ AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TaskSchedulerConfig.class);
//SchedulerService schedulerService = context.getBean(SchedulerService.class); } }

spring boot: @EnableScheduling开启计划任务支持,@Scheduled计划任务声明的更多相关文章

  1. Spring boot @EnableScheduling 和 @Scheduled 注解使用例子

    前言 Spring Boot提供了@EnableScheduling和@Scheduled注解,用于支持定时任务的执行,那么接下来就让我们学习下如何使用吧: 假设我们需要每隔10秒执行一个任务,那么我 ...

  2. spring boot 下 开启 gzip

    [参考文章]:Spring boot开启Gzip压缩 [参考文章]:Accept-Encoding Spring 版本 :5.1.2-RELEASE 1. application.yml 配置 ser ...

  3. Spring Boot同时开启HTTP和HTTPS服务

    由于Spring Boot中通过编码开启HTTPS服务比较复杂,所以官方推荐通过编码开启HTTP服务,而通过配置开启HTTPS服务. Spring Boot的application.yml中添加如下配 ...

  4. Spring Boot Ftp Client 客户端示例支持断点续传

    本章介绍 Spring Boot 整合 Ftpclient 的示例,支持断点续传 本项目源码下载 1 新建 Spring Boot Maven 示例工程项目 注意:是用来 IDEA 开发工具 File ...

  5. jersey在 spring boot 添加 packages 扫描路径支持

    最近公司内部系统要做数据对接,故使用 jersey 来做 restful webservice 接口设计.由于 spring boot 已经集成 jersey,估计直接导入 spring-boot-s ...

  6. Spring Boot笔记(四) springboot 集成 @Scheduled 定时任务

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 1.在SpringBoot 项目中使用@Scheduled注解执行定时任务: 配置pom.xml 依赖: ...

  7. spring boot 启动 开启注解 加载 bean

    业务描述:创建一个cache类然后交给spring 管理. @Component @Scope("singleton") public class Cache { public C ...

  8. spring boot 集成 quartz 定时任务

    spring boot: @EnableScheduling开启计划任务支持,@Scheduled计划任务声明 1.pom.xml 引入依赖 <dependency> <groupI ...

  9. Spring Boot中的缓存支持(一)注解配置与EhCache使用

    Spring Boot中的缓存支持(一)注解配置与EhCache使用 随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决 ...

随机推荐

  1. React-学习总结

    概念知识:1.JSX是什么 JSX其实是JavaScript的扩展,React为了代码的可读性更方便地创建虚拟DOM等原因,加入了一些类似XML的语法的扩展. 2.编译器——jsxTransforme ...

  2. 使用QtConcurrent编写多线程程序(也可以阻塞)

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Amnes1a/article/details/66470751Qt在其QtConcurrent命名空 ...

  3. mono下c#和c交互,字符串处理

    起因是ulua里,从luajit读字符串到c#里,做了编码转换,如下 public static string lua_tostring(IntPtr luaState, int index) { v ...

  4. 002 MIRO发票校验采购订单项目科目分配类别检查增强-20150819

    BADI SE19:ZINVOICE_UPDATE   MIRO发票检验过账好模拟时,检查采购订单line 是否有固定资产的行项目,如果有固定资产项目,则弹出提示框,提示消息:存在规定资产采购项目! ...

  5. C#托管代码 CLR

    托管代码 是直接编译成机器码,而是编译成中间语言 IL,由 CLR 托管运行. 托管代码就是把底层的一些操作(如内存的读取,释放)全都封装起来了,把有关内存管理的操作全都由CLR来管理, C#使用垃圾 ...

  6. active admin

    activeadmin 1.0.0.pre4 所依赖的库 gem 'jquery-rails', '~> 4.0.4' 4.2版本会出现找不到jquery-ui 的datepicker错误 使用 ...

  7. Python之 Django 初级

    Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Session等诸多功能. ...

  8. ThinkPHP框架基础知识一

    ThinkPHP是一个快速.兼容而且简单的轻量级国产PHP开发框架,诞生于2006年初,原名FCS,2007年元旦正式更名为ThinkPHP,遵循Apache2开源协议发布,从Struts结构移植过来 ...

  9. 【LeetCode】【矩阵旋转】Rotate Image

    描述 You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise ...

  10. python cookboo 文件与IO 函数

    写出文本数据 g = open('test.txt', 'rt', newline='',encoding = 'utf-8', errors='replace') t是windows平台特有的所谓t ...