赞
踩
- /**
- *
- * @author guokaige
- *
- */
- @Component
- public class BeanFactoryUtil implements ApplicationContextAware {
-
- protected static ApplicationContext ctx = null;
-
- @Override
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
- ctx = applicationContext;
- this.printAddress();
- }
-
- public static Object getBean(String beanId) {
- return ctx.getBean(beanId);
- }
-
- public void printAddress() {
- try {
- String host = InetAddress.getLocalHost().getHostAddress();
- TomcatServletWebServerFactory tomcatServletWebServerFactory = (TomcatServletWebServerFactory) ctx
- .getBean("tomcatServletWebServerFactory");
- int port = tomcatServletWebServerFactory.getPort();
- String contextPath = tomcatServletWebServerFactory.getContextPath();
- System.out.println("---------启动成功,访问: http://" + host + ":" + port + contextPath + "/");
- } catch (UnknownHostException e) {
- e.printStackTrace();
- }
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。