当前位置:   article > 正文

springboot项目启动后打印首页地址_springboot tomcat启动结束后打印图案

springboot tomcat启动结束后打印图案
  1. /**
  2. *
  3. * @author guokaige
  4. *
  5. */
  6. @Component
  7. public class BeanFactoryUtil implements ApplicationContextAware {
  8. protected static ApplicationContext ctx = null;
  9. @Override
  10. public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  11. ctx = applicationContext;
  12. this.printAddress();
  13. }
  14. public static Object getBean(String beanId) {
  15. return ctx.getBean(beanId);
  16. }
  17. public void printAddress() {
  18. try {
  19. String host = InetAddress.getLocalHost().getHostAddress();
  20. TomcatServletWebServerFactory tomcatServletWebServerFactory = (TomcatServletWebServerFactory) ctx
  21. .getBean("tomcatServletWebServerFactory");
  22. int port = tomcatServletWebServerFactory.getPort();
  23. String contextPath = tomcatServletWebServerFactory.getContextPath();
  24. System.out.println("---------启动成功,访问: http://" + host + ":" + port + contextPath + "/");
  25. } catch (UnknownHostException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/751156
推荐阅读
相关标签
  

闽ICP备14008679号