亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我收到此錯誤“EmbeddedServletContainerInitiali”

為什么我收到此錯誤“EmbeddedServletContainerInitiali”

蠱毒傳說 2023-03-17 15:40:59
我該如何解決 spring boot 中的這個錯誤?我正在嘗試獲取端口號和主機名,但我不斷收到此錯誤。@SpringBootApplicationpublic class RegistrationFormApplication implements ApplicationListener<EmbeddedServletContainerInitializedEvent> {    @Autowired    Environment environment;    public static void main(String[] args) {        SpringApplication.run(RegistrationFormApplication.class, args);    }    Logger logger;    @Override    public void onApplicationEvent(EmbeddedServletContainerInitializedEvent embeddedServletContainerInitializedEvent) {        logger.info("Port " + embeddedServletContainerInitializedEvent.getApplicationContext().getEmbeddedServletContainer().getPort());        try {           logger.info("HOST Address " + InetAddress.getLocalHost().getHostAddress());            logger.info("Host Name " + InetAddress.getLocalHost().getHostName());        } catch (UnknownHostException e) {        }    }}
查看完整描述

1 回答

?
MMMHUHU

TA貢獻1834條經驗 獲得超8個贊

可能是因為您在使用已刪除此類的 Spring Boot 2.x 時復制/粘貼了一些為 Spring Boot 1.x 編寫的代碼。

嘗試使用ServletWebServerInitializedEventport = event.getWebServer().getPort()。

有關獲取服務器端口的不同方法,請參閱https://self-learning-java-tutorial.blogspot.com/2018/07/spring-boot-get-port-of-spring-boot.html 。


查看完整回答
反對 回復 2023-03-17
  • 1 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號