@Component
public class Ports implements ApplicationListener<WebServerInitializedEvent> {
private int serverPort;
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
this.serverPort = event.getWebServer().getPort();
}
public int getPort() {
return this.serverPort;
}
}
SpringBoot动态获取端口号
最新推荐文章于 2022-06-04 23:30:17 发布
本博客介绍了一个简单的Spring Boot组件,该组件能够监听Web服务器初始化事件并从中获取服务器的实际端口号。
2115

被折叠的 条评论
为什么被折叠?



