代码git地址:github地址
首先版本号:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR2</spring-cloud.version>
</properties>
一共几个记忆点:
1、提供feign的项目的interface,注解@FeignClient的value 需要与该项目的application.yml中application.name相同,否则会报错:com.netflix.client.ClientException: Load balancer does not have available server for client: USER-SERVER3
正确样式如图:
2、在feignClient注解的方法中,如上图中的TestService中的方法sayHello,参数必须要加注解,如果不加注解,在其他项目中会无法传参到RestController的方法中去。否则会报错:feign.FeignException: status 405 reading TestService#sayHello(String); content: {"timestamp":"2019-07-05T06:05:45.679+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","path":"/hello2"}
3、对于feign的理解,这个@RestController更像是feignClient注解下interface的实现类。切记@RestController方法中mapping地址需要和@FeignClient下void的mapping地址一样。
同时网上很多说@GetMapping和PostMapping不能用的问题,我觉得也不存在,可能是我现在的版本支持吧