But the service registration has been successful
Why is this? I direct call service IP address can get return values
The service provider's controller classes and entry is as follows:
@ RestController
Public class HelloController {
Private final Logger Logger=Logger. GetLogger (getClass ());
The @autowired
Private DiscoveryClient client;
@ RequestMapping (value="https://bbs.csdn.net/hello", method=RequestMethod. GET)
Public String index () {
ListThe instances=client. GetInstances (" hello - service ");
for (int i=0; I & lt; The instances. The size (); I++) {
Logger. The info ("/hello, host: "+ instances. The get (I). The getHost () +", service_id: "+ instances. The get (I). GetServiceId ());
}
Return "Hello World".
}
}
@ EnableDiscoveryClient
@ SpringBootApplication
Public class ProviderApplication {
Public static void main (String [] args) {
SpringApplication. Run (ProviderApplication. Class, args);
}
}
The service consumer controller classes and entry:
@ RestController
Public class ConsumerController {
The @autowired
RestTemplate RestTemplate;
@ RequestMapping (value="https://bbs.csdn.net/ribbon-consumer", method=RequestMethod. GET)
Public String helloController () {
Return restTemplate. GetForEntity (" http://HELLO-SERVICE/hello ", String class). The getBody ();
}
}
@ SpringBootApplication
@ EnableDiscoveryClient
Public class RibbonConsumerApplication {
Public static void main (String [] args) {
SpringApplication. Run (RibbonConsumerApplication. Class, args);
}
@ LoadBalanced
@ Bean
RestTemplate RestTemplate () {
Return new RestTemplate ();
}
}
CodePudding user response:
The consumer endEureka configuration is correct?
CodePudding user response:
Because the value of your @ RequestMapping helloCodePudding user response:
I also met before, is the same as mine? https://blog.csdn.net/a729913162/article/details/81123078#commentsCodePudding user response:
Eureka. The instance. The hostname configuration is there, any deleted try againCodePudding user response:
I also met, just to solve in the consumer end write spring. When accessing a service application. The name of the name of external exposureCodePudding user response:
this is the publisher of eureka configuration, the source code at https://github.com/qpdyg/jih
Eureka:
Client:
Service - url:
DefaultZone: http://localhost:7001/eureka
# defaultZone: http://eureka7001.com:7001/eureka/, http://eureka7002.com:7002/eureka/, http://eureka7003.com:7003/eureka/
Instance:
The instance - id: jih - manage
-- - IP address: true
Server:
Enable - self - preservation: false
CodePudding user response:
There is something wrong with the RestTemplate injectionThe needs of the new injection:
@ Bean
@ LoadBalanced
RestOperations restTemplate (RestTemplateBuilder builder) {
Return builder. The build ();
}
The @autowired
RestOperations restTemplate;
CodePudding user response:
12th floor is a positive solution, for many daysCodePudding user response:
Excuse me, can you solve it, you and I appeared the same problem, 13 said 12 floor is a positive solution, can you try it, I don't know public RestOperations restTemplate (RestTemplateBuilder builder) {Return builder. The build ();
}
What is RestTemplateBuilder this parameter
CodePudding user response:
Why not feign brotherCodePudding user response:
The