首页 > 其他分享 >SpringBoot - 定时任务 @EnableScheduling,@Scheduled

SpringBoot - 定时任务 @EnableScheduling,@Scheduled

时间:2022-12-30 16:01:29浏览次数:50  
标签:Scheduled SpringBoot public cron EnableScheduling 定时 class

1.在启动类上添加@EnableScheduling注解,开启对定时任务的支持

//开启对定时任务的支持
@EnableScheduling
@SpringBootApplication
public class Learn20221218Application {
    public static void main(String[] args) {
        SpringApplication.run(Learn20221218Application.class, args);
    }
}

2.@Scheduled 注解,只能用在方法上

@Component
public class SchedulingService {
    @Scheduled(cron = "")
    public void scheduled(){

    }
}

cron 表达式生成器

标签:Scheduled,SpringBoot,public,cron,EnableScheduling,定时,class
From: https://www.cnblogs.com/ErenYeager/p/17015105.html

相关文章

  • SpringBoot参数校验
    原文:https://juejin.cn/post/6856541106626363399简单使用JavaAPI规范(JSR303)定义了Bean校验的标准validation-api,但没有提供实现。hibernatevalidation是对这个规范的......
  • SpringBoot - 异步任务 @EnableAsync,@Async
    1.在启动类上添加@EnabnleAsync注解开启对异步任务的支持//开启对异步任务的支持@EnableAsync@SpringBootApplicationpublicclassLearn20221218Application{p......
  • springboot HandlerIntercept
    1、新建上下文类工具类publicclassContextHolder{privatestaticfinalInheritableThreadLocal<RequestContext>REQUEST_CONTEXT_INHERITABLE_THREAD_LOCAL=......
  • 【MybatisPlus】SpringBoot快速集成MybatisPlus
    目录一、引入依赖二、逆向生成工具类三、其他配置 一、引入依赖<!--mysql--><dependency><groupId>mysql</groupId><artifactId>mysql-con......
  • 手把手的SpringBoot教程,SpringBoot创建web项目(三)
    这节课,我们来学习一下SpringBoot的环境配置,在SpringBoot中,所有的配置都写在application.properties中:我们启动项目,默认端口是8080,我们现在给他配置一个8088:server.port=808......
  • SpringBoot(九):整合Mybatis
    一、导入依赖<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId>......
  • 0016 常见错误com.example.adminspringboot.mapper.UserMapper.update
    错误截图  在使用mybatis中容易出现解决方法:在配置文件中加上路径书写:mybatis:mapper-locations:classpath:mapper/*.xml#扫描所有mapper下的xml文件 ......
  • springboot项目打包后上传服务器失败,但是在本地可以运行。
    近期开发一个项目,在本地运行无问题,发到服务器上无法访问,最后排查发现,springboot使用的是内嵌的tomcat,而项目要使用外部的tomcat。1.在pom文件里面去掉打包不参与的。<!--......
  • springboot简单了解
    先创建一下springboot工程,可以在idea里面创建,也可以在spring.io的官网里面创建,因为idea很卡,所以我一般用官网里面创建。  勾选起步依赖: 然后在程序中,对于控制器......
  • SpringBoot - WebMvcConfigurer 配置类
    WebMvcConfigurer:1.publicvoidconfigurePathMatch(PathMatchConfigurerconfigurer)路径匹配规则一般不用修改2.publicvoidconfigureContentNegotiation(ContentNe......