package com.qianwen.core.websocket.config;
|
|
import java.net.InetAddress;
|
import java.net.UnknownHostException;
|
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
import org.springframework.context.ApplicationListener;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
|
private int serverPort;
|
|
public int getServerPort() {
|
return this.serverPort;
|
}
|
|
public String getHost() {
|
InetAddress address = null;
|
try {
|
address = InetAddress.getLocalHost();
|
} catch (UnknownHostException e) {
|
e.printStackTrace();
|
}
|
return address.getHostAddress();
|
}
|
|
public void onApplicationEvent(WebServerInitializedEvent event) {
|
this.serverPort = event.getWebServer().getPort();
|
}
|
}
|