获取当前微服务端口号

版权声明:lpf https://blog.csdn.net/justlpf/article/details/83509257
package com.cloud.config;

import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author Administrator 2018/10/29
 */
@Component
public class IpConfiguration implements ApplicationListener<WebServerInitializedEvent> {
    private int serverPort;

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

    /**
     * @return 获取本微服务端口号
     */
    public int getPort() {
        return this.serverPort;
    }
}

猜你喜欢

转载自blog.csdn.net/justlpf/article/details/83509257