Home > Back-end >  Nacos newspaper UnknownHostException error call service
Nacos newspaper UnknownHostException error call service

Time:05-08

Local test, register the nacos - dojo.provide service, and then create nacos - consumer service call, see nacos console service has been registered, but whether I add @ LoadBalanced to RestTemplate annotations, is reported to the UnknownHostException errors, which the great spirit guide

===========================================
@ Bean
@ LoadBalanced
Public RestTemplate getRestTemple () {
Return new RestTemplate ();
}
===========================================
Java.net.UnknownHostException: nacos. Naming. ServiceName
At java.net.AbstractPlainSocketImpl.connect AbstractPlainSocketImpl. Java: (196) ~ [na: 1.8.0 comes with _281]
At java.net.PlainSocketImpl.connect PlainSocketImpl. Java: (162) ~ [na: 1.8.0 comes with _281]
At java.net.SocksSocketImpl.connect SocksSocketImpl. Java: (394) ~ [na: 1.8.0 comes with _281]
.
.


CodePudding user response:

@ GetMapping ("/consumer ")
Public String consumer () {
//by RestTemplate + Ribbon for service invocation using the service name
String result=restTemplate. GetForObject (" http://nacos-provide/helloNacos ", String class);
Return "return:" + result;
}
  • Related