zoukankan      html  css  js  c++  java
  • springboot启动项目时执行任务,从数据库或者redis获取系统参数

    在springboot启动类方法实现org.springframework.boot.CommandLineRunner接口

    import org.springframework.boot.CommandLineRunner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    
    @RestController
    @SpringBootApplication //Spring Boot核心注解,用于开启自动配置
    public class StartApplication implements CommandLineRunner{
    //程序可以直接在此启动
        @RequestMapping("/")
        String index(){
          return "ok";
        }
      
        public static void main(String[] args) {
            SpringApplication.run(StartApplication.class, args);
        }
        
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            //配置静态资源处理
            registry.addResourceHandler("/**")
            .addResourceLocations("classpath:/META-INF/")
            .addResourceLocations("classpath:/hospitalpay");
        }
    
        @Override
        public void run(String... args) throws Exception {
            //项目启动时会执行这里的任务
            //通常加载用于系统参数加载
        }
    }
  • 相关阅读:
    Java nio Socket非阻塞模式
    Android执行文件apk的组成结构
    C++大会归来
    C++大会的入场卷已入手
    DVB vs. SVB+Shader & Instancing
    放一个半年前写的Python静态检查编译器
    GCC 4.1 Released
    C++大会后的一些感想
    多核技术来临?
    Notepad++ v3.3 released
  • 原文地址:https://www.cnblogs.com/zyf-yxm/p/11423260.html
Copyright © 2011-2022 走看看