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 {
            //启动后执行该方法
        }
         
    }
  • 相关阅读:
    Activiti服务类-4 HistoryService服务类
    Activiti服务类-3 FormService服务类
    知识碎片
    web 框架
    pymysql 模块
    Bootstrap-按钮
    Bootstrap-下拉菜单
    前端之jQuery03 插件
    Python打印进度条
    JavaScript碎片
  • 原文地址:https://www.cnblogs.com/excellencesy/p/12373614.html
Copyright © 2011-2022 走看看