今天下午本机启动tomcat的时候遇到了一个问题。
严重: StandardServer.await: create[localhost:8005]:
java.net.BindException: Can't assign requested address
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:382)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:438)
at org.apache.catalina.startup.Catalina.await(Catalina.java:717)
at org.apache.catalina.startup.Catalina.start(Catalina.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
严重: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
java.io.IOException: Thread signal failed
at sun.nio.ch.NativeThread.signal(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.implCloseSelectableChannel(ServerSocketChannelImpl.java:292)
at java.nio.channels.spi.AbstractSelectableChannel.implCloseChannel(AbstractSelectableChannel.java:234)
at java.nio.channels.spi.AbstractInterruptibleChannel.close(AbstractInterruptibleChannel.java:115)
at sun.nio.ch.ServerSocketAdaptor.close(ServerSocketAdaptor.java:137)
at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:488)
at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:821)
at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:534)
at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:589)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:877)
at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:297)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:703)
at org.apache.catalina.startup.Catalina.start(Catalina.java:664)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
这种问题一般是由于 Mac 下 /etc/hosts文件的问题,可能是添加了无法解析绑定的ip。我的问题是host的软件将自身文件中的localhost ip改成了127.0.0.0。正常应该是127.0.0.1。
LookBack地址
特殊的IP地址段:
127.x.x.x
这是大家最熟悉不过的本地loopback地址,在windows和linux上等价于localhost。
我们习惯于使用127.0.0.1,实际上,
如果你在命令行下ping 127.0.0.1-127.255.255.254之间的任意地址,结果都是一样的,它们是等价的。
正常的网络包从ip层进入链路层,然后发送到网络上,
而发向loopback地址的包,直接在IP层短路了,也就是发到IP层的包直接被IP层接收了,不再向下发送。