zoukankan      html  css  js  c++  java
  • java spring boot 定时器

    java spring boot 定时器

    启动类加个

    @EnableScheduling

    package com.example.demo2122;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.scheduling.annotation.EnableScheduling;
    
    @SpringBootApplication
    @EnableScheduling
    public class Demo2122Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Demo2122Application.class, args);
        }
    
    
    
    
    }


    然后函数前面加个
     @Scheduled(fixedRate = 5000)


    package com.example.demo2122;
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    import javax.annotation.Resource;
    
    import java.util.*;
    @RestController
    @Component
    public class HelloControl {
    
        @GetMapping("/hello")
        public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
    
    
            return "fwef";
        }
        @Scheduled(fixedRate = 5000)
        public void scheduledTask1(){
            System.out.println("5秒执行一次");
        }
    
    
    }

    然后。就跑起来了。。。 

  • 相关阅读:
    来换网心得总结
    关于项目来换网
    数据库设计源代码
    自我介绍
    WC项目
    关于《现代软件工程》此书的疑问
    Swift基础语法(常量变量、数据类型、元组、可选、断言等)
    grunt快速学习
    Swift语言简介
    Swift简单入门教程:30分钟玩转Swift
  • 原文地址:https://www.cnblogs.com/newmiracle/p/12750400.html
Copyright © 2011-2022 走看看