spring boot中使用定时任务
1.在主类上添加EnableScheduling注解
package com.laoxu.gamedog;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
2.新建定时任务业务类
此处假设为:TestJob
package com.laoxu.gamedog.job;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 测试定时任务
*
* @author xusucheng
* @create 2018-12-03
**/
@Component
public class TestJob {
/**
* 每5秒钟执行一次
*/
@Scheduled(cron = "0/5 * * * * ?")
public void sayHello(){
System.out.println("Hello World at "+System.currentTimeMillis());
}
}
3.运行项目,查看效果

spring boot中使用定时任务的更多相关文章
- 【spring boot】spring boot中使用定时任务配置
spring boot中使用定时任务配置 =============================================================================== ...
- Spring Boot 中实现定时任务的两种方式
在 Spring + SpringMVC 环境中,一般来说,要实现定时任务,我们有两中方案,一种是使用 Spring 自带的定时任务处理器 @Scheduled 注解,另一种就是使用第三方框架 Qua ...
- Spring boot中的定时任务(计划任务)
从Spring3.1开始,计划任务在Spring中实现变得异常的简单.首先通过配置类注解@EnableScheduling来开启对计划任务的支持,然后再要执行的计划任务的方法上注释@Scheduled ...
- Spring Boot中使用@Scheduled创建定时任务
我们在编写Spring Boot应用中经常会遇到这样的场景,比如:我需要定时地发送一些短信.邮件之类的操作,也可能会定时地检查和监控一些标志.参数等. 创建定时任务 在Spring Boot中编写定时 ...
- 【定时任务】Spring Boot 中如何使用 Quartz
这篇文章将介绍如何在Spring Boot 中使用Quartz. 一.首先在 pom.xml 中添加 Quartz 依赖. <!-- quartz依赖 --> <dependency ...
- 如何在Spring Boot 中动态设定与执行定时任务
本篇文章的目的是记录并实现在Spring Boot中,动态设定与执行定时任务. 我的开发项目是 Maven 项目,所以首先需要在 pom.xml 文件中加入相关的依赖.依赖代码如下所示: <de ...
- 在Spring Boot中动态实现定时任务配置
原文路径:https://zhuanlan.zhihu.com/p/79644891 在日常的项目开发中,往往会涉及到一些需要做到定时执行的代码,例如自动将超过24小时的未付款的单改为取消状态,自动将 ...
- 【spring boot】使用定时任务@Scheduled 报错:Encountered invalid @Scheduled method 'dealShelf': Cron expression must consist of 6 fields (found 7 in "0 30 14 * * ? *")
在spring boot中使用使用定时任务@Scheduled 报错: org.springframework.beans.factory.BeanCreationException: Error c ...
- spring boot 基础篇 -- 定时任务
在日常项目中,常常会碰到定时监控项目中某个业务的变化,下面是spring boot 集成的定时任务具体配置: @Component public class IndexWarningScheduled ...
- Spring Boot中@Scheduled注解的使用方法
Spring Boot中@Scheduled注解的使用方法 一.定时任务注解为@Scheduled,使用方式举例如下 //定义一个按时间执行的定时任务,在每天16:00执行一次. @Scheduled ...
随机推荐
- [转帖]Linux 上 SQL Server 2022 (16.x) 的各版本和支持的功能
https://zhuanlan.zhihu.com/p/371869456 本文内容 SQL Server 版本 将 SQL Server 用于客户端/服务器应用程序 SQL Server 组件 ...
- [转帖]关于虚拟化中cpu的指令集SSE 4.2的不支持
背景: 局域网中有两台服务器proxmox进行了虚拟化,跑一些测试应用.今天正好想要安装一下clickhouse跑一下.安装前准备: 测试服务器是否支持sse 4.2指令集-如下 [root@slav ...
- [转帖]比快更快的 ELK 8 安装使用指南-Elasticsearch,Kibana,Logstash
https://juejin.cn/post/7133907643386560519 携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第23天,点击查看活动详情 Elastic 8 ...
- [转帖]安全技术和iptables防火墙
目录 安全技术 Netfilter 防火墙工具介绍 iptables firewalld nftables iptables的组成概述 netfilter与iptables关系 iptables的四表 ...
- [转帖]Linux平台shell脚本输入密码,不显示明文
需求:shell脚本中输入密码,要求不显示明文,需要将其转换为"*"星号,或者不显示 实现方案:有两种实现方案,一是通过stty命令来实现,二是直接使用read来实现 方案一:使用 ...
- [转帖]Arm发布CortexX4,功耗可降低40%
https://www.eet-china.com/mp/a224124.html ARM 发布了新一代的移动处理器内核,包括 Cortex-X4.Cortex-A720.Cortex-A520,预计 ...
- Windows 和 linux 下面 Redis 性能比较
Windows 和 linux 下面 Redis 性能比较 问题来源 公司里面有一些环境还是使用Windows来跑 对应的. Redis和nginx 也是跑在Windows上面 但是微软官网自从 3. ...
- 截止2021年linux发行版
- 让一段代码执行在new Vue之前
这是一个自调用函数,也有人叫做一次性函数: 这样函数前面最后打一个: ;(function initApp(){ loadApp(); })() function loadApp (){ //tena ...
- 如何在centos7中完全卸载Python3
如何在centos7中完全卸载Python3?根据查到的资料,主要就是卸载,然后删除一些软连接删除干净,逻辑很简单,贴一些具体的操作代码,记录下来 . 卸载Python3的步骤 #卸载python3 ...