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使用 随着时间的积累,应用的使用用户不断增加,数据规模也越来越大,往往数据库查询操作会成为影响用户使用体验的瓶颈,此时使用缓存往往是解决 ...
随机推荐
- jQuery-PHP跨域请求数据
jQuery: //获取域名 function getDomain(url){ var a = document.createElement('a'); a.href = url; url=a.hos ...
- Thinking In Myself
what is the I want to be? you know yourself? what is your dream? your interest? your passion? why y ...
- 剑指offer 面试14题
面试14题: 题目:剪绳子 题:给你一根长度为n的绳子,请把绳子剪成m段(m,n都是整数,且n>1,m>1),每段绳子的长度记为k[0],k[1],k[2],...,k[m].请问k[0] ...
- 前端之JQuery [续]
JQuery使用技巧 1.prop属性实现全选,反选,取消功能 需求: 实现全选,反选,取消功能 代码如下: <!DOCTYPE html> <html lang="en& ...
- InnoDB存储引擎内存缓冲池管理技术——LRU List、Free List、Flush List
InnoDB是事务安全的MySQL存储引擎,野山谷OLTP应用中核心表的首选存储引擎.他是基于表的存储引擎,而不是基于数据库的.其特点是行锁设计.支持MVCC.支持外键.提供一致性非锁定读,同时被设计 ...
- cocos打包出现错误,执行命令出错,返回值:2。 Traceback (most recent call last): File "E:\cocos_workspace\MyGameOne\proj.android\build_native.py", line 43, in <module> build(opts.build_mode) File "E:\cocos_workspace\MyGa
先看看NDK的版本,如果不行,就删除\proj.android\obj\local\armeabi下的文件.
- 【TopCoder】SRM160 DIV1总结
做了两道题之后才发现做的是DIV1,不是DIV2,DIV1的第二道题是DIV1的第三道题,果断决定第3题就不看了=.= 250分题:给定一个时间起点8:00 AM DAY 1,再给出一组时间终点,格式 ...
- 前端之CSS样式
一.CSS 1.什么是CSS 层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的 ...
- IOS中大文件拷贝算法
+ (void)copyFileFromPath:(NSString *)fromPath toPath:(NSString *)toPath { //每次读取数据大小 #define READ_SI ...
- Java线程池ExecutorService和CountDownLatch的小例子
import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java ...