Spring boot 启动监听器 [英] Spring boot startup listener

查看:37
本文介绍了Spring boot 启动监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We are running spring boot application as a background process, so we do not have access to startup log, is there a way to know after the boot startup process is complete?

推荐答案

spring boot 进程启动完成后可以选择执行一些代码,启动完成后可以发送启动完成通知.

You can choose to execute some code after spring boot process is finished its startup, when startup completed you can send a notification about startup completed.

@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.

Just implement the CommandLineRunner as shown above.

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

这篇关于Spring boot 启动监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆