[英]Print application banner when Spring Context starts
I'm trying to implement an application Banner that prints the version and other information when our application starts. 我正在尝试实现一个应用程序横幅,该横幅广告会在我们的应用程序启动时打印版本和其他信息。 I have tried implementing SmartLifecycle and ApplicationListener without success. 我尝试实现SmartLifecycle和ApplicationListener失败。
The callback method never gets called and the banner never prints. 永远不会调用回调方法,也不会打印横幅。 What am I doing wrong? 我究竟做错了什么?
public class Banner implements ApplicationListener<ContextStartedEvent>
{
private static final Logger log = LoggerFactory.getLogger(Banner.class);
@Override
public void onApplicationEvent(ContextStartedEvent event)
{
log.info("*******************************************************");
log.info("Application v1.8 starting");
log.info("*******************************************************");
}
}
ContextStartedEvent
is raised only when ConfigurableApplicationContext.start()
method is invoked. 仅当调用ConfigurableApplicationContext.start()
方法时,才会引发ContextStartedEvent
。 Use ContextRefreshedEvent
instead of ContextStartedEvent
使用ContextRefreshedEvent
代替ContextStartedEvent
Documentation: 文档:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#context-functionality-events http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#context-functionality-events
If you use spring-boot, the below solution will work for you. 如果您使用spring-boot,下面的解决方案将为您工作。
Use ASCII art generator OR Use Spring Boot Banner Generator ; 使用ASCII艺术生成器或使用Spring Boot标语生成器 ; If you want to use any "image" to generate a banner for your Spring Boot application. 如果您想使用任何“图像”为您的Spring Boot应用程序生成横幅。
Copy the generated ASCII characters into /src/main/resources/banner.txt 将生成的ASCII字符复制到/src/main/resources/banner.txt
Start the spring-boot application. 启动spring-boot应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.