SpringCloud Feign传对象参数调用失败的问题

  • 不支持GET请求方式
  • 使用Apache HttpClient替换Feign原生httpclient
  • @RequestBody接收json参数

bootstrap-local.yml

feign:
  httpclient:
    enabled: true

pom.xml

<!-- 使用Apache HttpClient替换Feign原生httpclient -->
<dependency>
    <groupId>com.netflix.feign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>8.18.0</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
</dependency>

feignClient:

@FeignClient(name = "hd-ucenter-server", fallback = SysTestServerFallbackImpl.class)
public interface SysTestServer {

    @RequestMapping(value = "/test/test", method = RequestMethod.POST, consumes = "application/json")
    Object test(CurrentUser currentUser);

}

RestController:

@RestController
@PostMapping("/test")
public class TestController {

    @RequestMapping(value = "/test")
    public Object test(@RequestBody CurrentUser currentUser) {
        System.out.printf("调用test\n");
       return currentUser;
    }

}


猜你喜欢

转载自blog.csdn.net/itdragons/article/details/80927560