Service calls between Feign

Feign is to simplify Java HTTP client development tool (java-to-httpclient-binder), which was inspired by Retrofit, JAXRS-2.0 and WebSocket. Feign intention is to reduce the complexity of unified Denominator bind to the HTTP API, does not distinguish whether it is restful.
 
Add dependent 
<dependency> 
    <groupId>org.springframework.cloud</groupId> 
    <artifactId>spring‐cloud‐starter‐openfeign</artifactId> 
</dependency>

Add comment startup class 

  @EnableDiscoveryClient

   @EnableFeignClients

Create a client package 

  Creating interfaces 

@FeignClient ( "API-Base" ) // call the function from which the service, pay attention to which name and service name to be called consistent, and can not contain underscore
public  interface LabelClient { 
@RequestMapping (value = "/ Test / {ID}", Method = RequestMethod.GET) // @ @RequestMapping annotation for micro-called service address mapping. Note @PathVariable notes must specify the parameter name, otherwise the wrong
public the Result findById (@PathVariable ( "the above mentioned id") String the above mentioned id);}

transfer 

@Autowired 
private LabelClient labelClient; 
@RequestMapping(value
= "/test/{testid}") public Result findById(@PathVariable String testid){   Result result = labelClient.findById(labelid);
  return result;
}

feign integrated load balancing 

 

 

 

Guess you like

Origin www.cnblogs.com/qin1993/p/12566225.html