版权声明: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;
}
}