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文件的话很容易找不到原因,所以记录一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值