【问题标题】:Spring boot startup listenerSpring Boot 启动监听器
【发布时间】:2017-04-12 10:46:01
【问题描述】:

我们将spring boot应用作为后台进程运行,所以我们无法访问启动日志,有没有办法在boot启动过程完成后知道?

【问题讨论】:

    标签: spring spring-mvc spring-boot


    【解决方案1】:

    您可以选择在spring boot过程完成启动后执行一些代码,当启动完成时您可以发送启动完成的通知。

    @SpringBootApplication
    @Component
    public class Application implements CommandLineRunner {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
        @Override
        public void run(String... arg0) throws Exception {
            // You can write your code here.
            // This code will be executed after Spring Boot Startup completed. 
    
        }
    }
    

    只需如上所示实现 CommandLineRunner 即可。

    http://docs.spring.io/spring-boot/docs/1.5.2.RELEASE/reference/htmlsingle/#boot-features-command-line-runner

    【讨论】:

      猜你喜欢
      • 2018-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      • 2021-10-15
      • 2021-03-11
      • 2017-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多