zoukankan      html  css  js  c++  java
  • Spring Boot项目指定启动后执行的操作

    Spring Boot项目指定启动后执行的操作:

    (1)实现CommandLineRunner 接口

    (2)重写run方法

    (3)声明执行顺序@Order(1),数值越小,优先级越高

    (4)如果需要注入service或者component等类,再加上@Component注解

    package com.googosoft.gateway_zuul;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.core.annotation.Order;
    import org.springframework.stereotype.Component;
    
    /**
     * 该类在springboot启动之后执行run方法
     * @author songyan
     * @date 2020年2月27日
     */
    @Component
    @Order(1)
    public class ApplicationInitor implements CommandLineRunner {
         
        @Value("${monitorPlatformUrl}")
        private String monitorPlatformUrl;
    
        @Override
        public void run(String... args) throws Exception {
            //启动后执行该方法
        }
         
    }
  • 相关阅读:
    java 使用相对路径读取文件
    appium 使用过程问题踩坑-笔记
    CentOS下启动Tomcat
    jodis遇到的问题
    CentOS 7.0 防火墙
    sentinel
    keepalived
    在Tomat7上使用Redis保存Session
    Log4j 使用
    java路径问题
  • 原文地址:https://www.cnblogs.com/excellencesy/p/12373614.html
Copyright © 2011-2022 走看看