zoukankan      html  css  js  c++  java
  • 获取ip和端口号

    package com.sf.confirmation.core.config;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.boot.web.context.WebServerInitializedEvent;
    import org.springframework.context.ApplicationListener;
    import org.springframework.stereotype.Component;
    import org.water.common.exception.SysException;

    import java.net.InetAddress;
    import java.net.UnknownHostException;

    /**
    * @author 80004084
    * @date 2019/9/30 15:18
    * @description :获取ip和端口号
    */
    @Component
    public class InternetInfo implements ApplicationListener<WebServerInitializedEvent> {

      private final static Logger LOGGER = LoggerFactory.getLogger(InternetInfo.class);

      private int serverPort;

      @Override
      public void onApplicationEvent(WebServerInitializedEvent event) {  
        this.serverPort = event.getWebServer().getPort();
      }

      public int getPort() {
        return this.serverPort;
      }

      public String getLocalHostAddress() {
        InetAddress address = null;
      try {
        address = InetAddress.getLocalHost();
      } catch (UnknownHostException e) {
        LOGGER.error("UnknownHostException:",e);
        throw new SysException("获取服务器ip和端口失败");
      }
      return address.getHostAddress() + ":" + getPort();
      }

    }

  • 相关阅读:
    Luogu2751 [USACO Training4.2]工序安排Job Processing
    BZOJ4653: [Noi2016]区间
    BZOJ1537: [POI2005]Aut- The Bus
    CF1041F Ray in the tube
    POJ1186 方程的解数
    Luogu2578 [ZJOI2005]九数码游戏
    BZOJ2216: [Poi2011]Lightning Conductor
    CF865D Buy Low Sell High
    BZOJ1577: [Usaco2009 Feb]庙会捷运Fair Shuttle
    几类区间覆盖
  • 原文地址:https://www.cnblogs.com/pxzbky/p/11779638.html
Copyright © 2011-2022 走看看