Spring boot创建定时任务
基于spring boot的应用创建定时任务不要太简单,给一个类加上@Configuration @EnableScheduling注解,然后给该类需要定时执行的方法加上@Scheduled(cron = "${case.phase.cron}")注解。就OK了。
${case.phase.cron}表示case.phase.cron从应用配置文件application.properties里取,或者从config-server里取。对应的cron表达式case.phase.cron=0 0/1 * * * ? 代表1分钟执行一次。
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; /**
* 定时任务
* 去调用办件状态查询标准接口
* */
@Configuration
@EnableScheduling
public class CasePhaseTaskService {
private static final Logger LOGGER = LoggerFactory.getLogger(CasePhaseTaskService.class);
@Scheduled(cron = "${case.phase.cron}")
public void execScheduledTask() {
LOGGER.info("task开始..."); LOGGER.info("task结束!");
}
}
Spring boot创建定时任务的更多相关文章
- spring boot 创建定时任务
@Scheduled默认创建的线程是单线程,任务的执行会受到上一个任务的影响,创建定时任务也比较简单 123456789101112 @Component@Configuration //1.主要用于 ...
- Spring Boot 创建定时任务(配合数据库动态执行)
序言:创建定时任务非常简单,主要有两种创建方式:一.基于注解(@Scheduled) 二.基于接口(SchedulingConfigurer). 前者相信大家都很熟悉,但是实际使用中我们往往想从数据库 ...
- Spring Boot配置定时任务
在项目开发过程中,经常需要定时任务来做一些内容,比如定时进行数据统计(阅读量统计),数据更新(生成每天的歌单推荐)等. Spring Boot默认已经实现了,我们只需要添加相应的注解就可以完成定时任务 ...
- Spring Kafka整合Spring Boot创建生产者客户端案例
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 创建一个kafka-producer-master的maven工程.整个项目结构如下: ...
- 利用spring boot创建java app
利用spring boot创建java app 背景 在使用spring框架开发的过程中,随着功能以及业务逻辑的日益复杂,应用伴随着大量的XML配置和复杂的bean依赖关系,特别是在使用mvc的时候各 ...
- spring cloud教程之使用spring boot创建一个应用
<7天学会spring cloud>第一天,熟悉spring boot,并使用spring boot创建一个应用. Spring Boot是Spring团队推出的新框架,它所使用的核心技术 ...
- 【spring boot】5.spring boot 创建web项目并使用jsp作前台页面
贼烦的是,使用spring boot 创建web项目,然后我再idea下创建的,but 仅仅启动spring boot的启动类,就算整个项目都是好着的,就算是能够进入controller中,也不能成功 ...
- Spring Boot 创建hello world项目
Spring Boot 创建hello world项目 1.创建项目 最近在学习Spring Boot,这里记录使用IDEA创建Spring Boot的的过程 在1出勾选,选择2,点击Next 这里填 ...
- 【Spring Boot】定时任务
[Spring Boot]定时任务 测试用业务Service package com.example.schedule.service; import org.springframework.ster ...
随机推荐
- OC 线程操作3 - NSOperation
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- B/S与C/S的比较
1.C/S需要安装客户端软件,比如我们的qq就是C/S模式下的软件.如果使用这些软件我们必须先要下载客户端软件.如果软件更新了,就需要下载新的客户端进行更新. 2.B/S无需安装客户端软件,比如我们的 ...
- .net 4.0的Lazy<T>方法,反射实现延迟加载。
//自己山寨.public class YaLazy<T> { private bool _isValueCreated = false; public bool IsValueCreat ...
- Macbook pro睡眠状态恢复后没声音的解决办法
杀招: sudo killall coreaudiod macos会自动重启进程,恢复声音
- DB2事务日志
1.DB2数据库的日志原理 事务日志记录数据库中所有对象和数据的改变,在早前版本中最大可达256G,其大小为( logprimary + logsecond ) * logfilsiz,其中logpr ...
- PAT 1072 开学寄语(20)(代码+思路)
1072 开学寄语(20 分) 下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面.理发.整衣, ...
- Codeforces 689C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves time limit per test:2 seconds memory limit per test:256 megabytes inpu ...
- system v消息队列demo(未编译)
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> ...
- 二进制搭建kubernetes多master集群【四、配置k8s node】
上一篇我们部署了kubernetes的master集群,参考:二进制搭建kubernetes多master集群[三.配置k8s master及高可用] 本文在以下主机上操作部署k8s node k8s ...
- 26. The Greenhouse Effect and Its Consequences 温室效应及其后果
26. The Greenhouse Effect and Its Consequences 温室效应及其后果 ①The greenhouse effect causes trouble by rai ...