嚴重: StandardServer.await: create[8005]:
java.net.BindException: Cannot assign requested address: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:406)
at org.apache.catalina.startup.Catalina.await(Catalina.java:676)
...
netstat -an 確認 8080/8005 無佔用,修改 server.xml 埠口仍失效localhost 所有 IP 並逐個綁定C:\Windows\System32\drivers\etc\hosts# 問題 hosts 內容
127.0.0.1 localhost
169.196.254.14 localhost <-- 這個 IP 不存在於本機網卡
Tomcat 嘗試綁定 169.196.254.14 失敗,拋出 BindException。
刪除 hosts 中錯誤的 IP 映射行,保留標準回環:
127.0.0.1 localhost
::1 localhost
重啟 Tomcat 即恢復正常。
InetAddress[] ips = InetAddress.getAllByName("localhost");
if (ips != null) {
for (InetAddress ip : ips) {
System.out.println(ip.getHostAddress());
}
}
// 修正前輸出:169.196.254.14, 127.0.0.1
// 修正後輸出:127.0.0.1
InetAddress.getAllByName("localhost") 的 Java 應用127.0.0.1 明確綁定<Server port="8005" shutdown="SHUTDOWN" address="127.0.0.1">
<Connector port="8080" protocol="HTTP/1.1" address="127.0.0.1" />
明確指定 address="127.0.0.1" 避免綁定異常 IP。