获取容器端口的方式

Posted by KANG's BLOG on Saturday, March 5, 2022

获取容器端口的方式

@Component
public class PortConfiguration implements ApplicationListener<WebServerInitializedEvent> {

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