springboot2.0 獲取啟動埠號

weixin_34315665發表於2018-03-20

如下:

>public class ConfSerivce  implements ApplicationListener<WebServerInitializedEvent>{
>@Override
>   public void onApplicationEvent(WebServerInitializedEvent event) {
>       try {
>           int port = event.getWebServer().getPort();
>           
>       } catch (Exception e) {
>           e.printStackTrace();
>       }
>   }
>}

相關文章