您当前的位置: 首页 >  Java

命运之手

暂无认证

  • 3浏览

    0关注

    747博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Java】【Spring】SpringBoot中添加监听器

命运之手 发布时间:2019-07-09 10:45:57 ,浏览量:3

添加一个监听器,在项目完全启动后,打印项目地址


@Component
public class ContextListener implements ApplicationListener {

    @Override
    @SneakyThrows
    public void onApplicationEvent(ApplicationReadyEvent event) {
        String host = InetAddress.getLocalHost().getHostAddress();
        TomcatServletWebServerFactory factory = (TomcatServletWebServerFactory) event.getApplicationContext().getBean("tomcatServletWebServerFactory");
        int port = factory.getPort();
        String path = factory.getContextPath();
        String url = "http://" + host + ":" + port + path;
        Console.print(ContextListener.class, "项目启动成功 " + url);
    }
}  

关注
打赏
1654938663
查看更多评论
立即登录/注册

微信扫码登录

0.0373s