java.net.UnknownHostException: 不知道这样的主机。

在本地跑一个nacos项目运行的时候碰到了个这个错误

java.net.UnknownHostException: 不知道这样的主机。 (\项目名)
	at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
	Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
	Error has been observed at the following site(s):
	|_ checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
	|_ checkpoint ⇢ HTTP GET "请求接口" [ExceptionHandlingWebHandler]
Stack trace:
		at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
		at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:933) ~[na:na]
		at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1519) ~[na:na]
		at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:852) ~[na:na]
		at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1509) ~[na:na]
		at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1367) ~[na:na]
		at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1301) ~[na:na]
		at java.base/java.net.InetAddress.getByName(InetAddress.java:1251) ~[na:na]
		at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:156) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.util.internal.SocketUtils$8.run(SocketUtils.java:153) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]
		at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) ~[na:na]
		at io.netty.util.internal.SocketUtils.addressByName(SocketUtils.java:153) ~[netty-common-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.resolver.DefaultNameResolver.doResolve(DefaultNameResolver.java:41) ~[netty-resolver-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:61) ~[netty-resolver-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.resolver.SimpleNameResolver.resolve(SimpleNameResolver.java:53) ~[netty-resolver-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:55) ~[netty-resolver-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.resolver.InetSocketAddressResolver.doResolve(InetSocketAddressResolver.java:31) ~[netty-resolver-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.resolver.AbstractAddressResolver.resolve(AbstractAddressResolver.java:106) ~[netty-resolver-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.bootstrap.Bootstrap.doResolveAndConnect0(Bootstrap.java:206) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.bootstrap.Bootstrap.access$000(Bootstrap.java:46) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:180) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]
		at io.netty.bootstrap.Bootstrap$1.operationComplete(Bootstrap.java:166) ~[netty-transport-4.1.55.Final.jar:4.1.55.Final]

解决方案

  1. 找到C:\Windows\System32\drivers\etc\HOSTS文件
  2. 加一行代码 127.0.0.1 项目名

原因

别问,问就是需要映射

遇到这种错误的时候,如果没有思路或者很久没有用到过hosts文件的话很容易找不到原因,所以记录一下

你可能感兴趣的:(工具使用中遇到的一些问题,java,.net,开发语言)