zoukankan      html  css  js  c++  java
  • SpringBoot中Scheduled代码实现

    新建Maven项目SpringQuartz。

    1.1 添加依赖

    由于spring-boot-starter-web并没有依赖spring-conext-support,所以需要单独添加此依赖。

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.10.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
        </dependency>
    </dependencies>
    

      

    1.1 创建启动类

    新建com.bjsxt.QuartzApplication启动类

    @SpringBootApplication
    @EnableScheduling
    publ class QuartzApplication {
        public static void main(String[] args) {
            SpringApplication.run(QuartzApplication.class,args);
        }
    }

    1.1 新建定时任务

    新建com.bjsxt.scheduled.DemoScheduled类。

    注意类上有@Component注解,启动项目就需要加载类及类中的@Scheduled注解。

    @Component
    public class DemoScheduled {
        @Scheduled(cron="0/2 * * * * *")
        public void testScheduled(){
            System.out.println("test scheduled");
        }
    }
    

      

  • 相关阅读:
    electrica writeup
    C++ Tips and Tricks
    net-force.nl/steganography writeup
    3*n/2
    C++ 关键字浅谈
    MindMaster激活教程
    gitignre
    python pil 安装
    ubuntu 阿里云安全配置
    阿里云 centos 环境配置与 django 部署
  • 原文地址:https://www.cnblogs.com/vincentmax/p/14335554.html
Copyright © 2011-2022 走看看