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. Creating a Message Queue in PHP Without External Libraries

    w http://www.ebrueggeman.com/blog/creating-a-message-queue-in-php

  2. Kuratowski's and Wagner's theorems

    w https://en.wikipedia.org/wiki/Planar_graph The Polish mathematician Kazimierz Kuratowski provided ...

  3. Nuxt使用scss

    Nuxt中使用scss也很简单,分简单的几步就OK 一.安装scss依赖 用IDE打开项目,在Terminal里通过 npm i node-sass sass-loader scss-loader - ...

  4. Linux中的服务管理

    RPM包默认安装的服务 查看已安装的服务: chkconfig --list 默认安装位置: /etc/init.d 启动脚本 /etc/sysconfig 初始化环境配置文件 /etc  配置文件位 ...

  5. always on 技术

    always on 技术系列:https://blog.csdn.net/dba_huangzj/article/details/54015470 MSSQL 2014 /WIN SERVER 200 ...

  6. Linux三种网络

    Host-Only 桥接

  7. Android-实现切换Fragment页功能

    场景:使用Fragment实现切页. 类结构: 一:Activity Activity中使用getSupportFragmentManager().beginTransaction()来填充一个Fra ...

  8. python读写Excel文件--使用xlrd模块读取,xlwt模块写入

    一.安装xlrd模块和xlwt模块 1. 下载xlrd模块和xlwt模块 到python官网http://pypi.python.org/pypi/xlrd下载模块.下载的文件例如:xlrd-0.9. ...

  9. 在C#中动态编译T4模板代码

    转: http://www.wxzzz.com/1438.html 资料: https://cnsmartcodegenerator.codeplex.com/SourceControl/latest ...

  10. loadrunder之脚本篇——脚本基础知识和常用操作

    1)编码工具设置 自动补全输入Tools->General Options->Environment->Auto complete word 显示功能语法Tools->Genr ...