环境 Springboot3.0.2,SpringCload22.0.0
服务都已经注册到nacos了,但是在使用RestTemplate 调用服务提供者时报错
java.net.UnknownHostException: nacos-payment-provider
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:560) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:666) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:600) ~[na:na]
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183) ~[na:na]
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:531) ~[na:na]
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:636) ~[na:na]
这是因为nacos在2021年之前不再默认集成Ribbon,所以需要在调用项目的pom文件中添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
评论区