spring boot: @EnableScheduling开启计划任务支持,@Scheduled计划任务声明
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计划任务声明的更多相关文章
- Spring boot @EnableScheduling 和 @Scheduled 注解使用例子
前言 Spring Boot提供了@EnableScheduling和@Scheduled注解,用于支持定时任务的执行,那么接下来就让我们学习下如何使用吧: 假设我们需要每隔10秒执行一个任务,那么我 ...
- spring boot 下 开启 gzip
[参考文章]:Spring boot开启Gzip压缩 [参考文章]:Accept-Encoding Spring 版本 :5.1.2-RELEASE 1. application.yml 配置 ser ...
- Spring Boot同时开启HTTP和HTTPS服务
由于Spring Boot中通过编码开启HTTPS服务比较复杂,所以官方推荐通过编码开启HTTP服务,而通过配置开启HTTPS服务. Spring Boot的application.yml中添加如下配 ...
- Spring Boot Ftp Client 客户端示例支持断点续传
本章介绍 Spring Boot 整合 Ftpclient 的示例,支持断点续传 本项目源码下载 1 新建 Spring Boot Maven 示例工程项目 注意:是用来 IDEA 开发工具 File ...
- jersey在 spring boot 添加 packages 扫描路径支持
最近公司内部系统要做数据对接,故使用 jersey 来做 restful webservice 接口设计.由于 spring boot 已经集成 jersey,估计直接导入 spring-boot-s ...
- Spring Boot笔记(四) springboot 集成 @Scheduled 定时任务
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 1.在SpringBoot 项目中使用@Scheduled注解执行定时任务: 配置pom.xml 依赖: ...
- spring boot 启动 开启注解 加载 bean
业务描述:创建一个cache类然后交给spring 管理. @Component @Scope("singleton") public class Cache { public C ...
- spring boot 集成 quartz 定时任务
spring boot: @EnableScheduling开启计划任务支持,@Scheduled计划任务声明 1.pom.xml 引入依赖 <dependency> <groupI ...
- Spring Boot中的缓存支持(一)注解配置与EhCache使用
Spring Boot中的缓存支持(一)注解配置与EhCache使用 随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决 ...
随机推荐
- Oracle DBA的学习(笔记)
1.软件任务分组:系统分析师.系统设计师.程序员.测试人员.开发dba.系统架构师.实施人员. 2.常用设计图:活动图.用例图.类图.序列图. 2010-9-15(dba学习) 1.1 Oracle产 ...
- JS获取短信验证码60秒
<script language="javascript"> function get_mobile_code(){ $.post("{{ ...
- 我的Android进阶之旅------>修改Android签名证书keystore的密码、别名alias以及别名密码
转载于:http://blog.k-res.net/archives/1229.html 和 http://blog.k-res.net/archives/1671.html ADT允许自定义调试用 ...
- 我的Android进阶之旅------>HTTP Content-type 对照表
HTTP Content-type 对照表 文件扩展名 Content-Type(Mime-Type) 文件扩展名 Content-Type(Mime-Type) .*( 二进制流, 不知道下载文件类 ...
- Linux中进程在前后台的切换
把进程放入后台执行 tar -zcf etc.tar.gz /etc &把进程放入后台暂停 在命令执行的过程中,按下ctrl+z 查看后台的命令 jobs[root@localhost tem ...
- tomcat8.5.11的manager页面总是提示403的问题
修改conf/tomcat-users.xml加入: <role rolename="manager"/> <role rolename="manage ...
- ACM解题之回文序列
题意: 一个长度为 n 的序列 a1, m2, ..., an-1, an,如果 ai = an-i+1, i = 1, 2, ..., n,则称之为"回文序列".本题对于给定的一 ...
- 前端基础之JavaScript_(2)_BOM对象
BOM对象 window对象 所有浏览器都支持 window 对象.概念上讲.一个html文档对应一个window对象.功能上讲: 控制浏览器窗口的.使用上讲: window对象不需要创建对象,直接使 ...
- 每天一个Linux命令(53)service命令
service命令用于对系统服务进行管理. (1)用法: 用法: service [服务] [操作] (2)功能: 功能: service命令用于启动.停止.重 ...
- oracle 定时删除3天前的备份数据
不需要保留那么多,按公司要求只需要保留一个星期的即可. 1.那么有什么方法自动删除7天以前备份的*.log文件呢? 2.服务器过多,不可能一一手动创建,有没有自动完成这个创建计划任务的批处理呢? 首先 ...