Feign Client + Eureka POST请求正文

时间:2016-02-08 07:46:48

标签: spring rest microservices netflix-eureka netflix-feign

我正在尝试使用Feign和Eureka将邮件请求从服务器A转发到服务器B.这两台服务器都被Eureka成功推出。

这有效:

@Feignclient
public interface MyFeignClient {
    @RequestMapping(value = "test", = RequestMethod.POST, consumes = "application/json")
    ResponseEntity<String> theActualMethod(
            HttpServletRequest request,
            @RequestHeader("firstHeader") String header1,
            @RequestHeader("secondHeader") byte[] header2);
}

但是,当我将第二个参数更改为@RequestBody以便读取POST请求内容时,我得到一个例外:

java.lang.IllegalStateException: Method has too many Body parameters: public abstract org.springframework.http.ResponseEntity MyFeignClient.theActualMethod(javax.servlet.http.HttpServletRequest,java.lang.String,byte[])

2 个答案:

答案 0 :(得分:6)

问题是Feign界面中的方法不能有多个一般的&#39;论点。您可以拥有任意数量的标头参数,但不能超过一个作为正文。由于@RequestBody没有做任何事情,因此除了HttpServletRequest请求变量之外,它不被视为标题而是另一个变量。

所以我不得不改变我的业务逻辑只有一个参数。

答案 1 :(得分:0)

对我来说,问题是我使用.textInfo { border: solid 1px lightblue; } .textInfo:hover { background-color: #e8a4c9; color: #fff; } .innerText-cupCake { display: none; } .innerText-cheeseCake { display: none; } .item { background-color: lightblue; width: 200px; padding: 5px; text-align: center; } .item:hover { background-color: #e8a4c9; }(如<div class="wrapper"> <div class="box pastries" id="pastries"> <div data-target="1" id="cupcake" class="box item cupcake">Cupcake</div> <div data-target="2" id="cheesecake" class="box item cheesecake">Cheesecake</div> </div> <div class="box textInfo" id="textInfo"> <h2>Please, select a category first!</h2> <div data-index="1" class="innerText-cupCake"> <p>Ice cream fruitcake cotton candy.</p> </div> <div data-index="2" class="innerText-cheeseCake"> <p>Chocolate sweet roll chupa chups bonbon macaroon.</p> </div> </div> </div>)而不是@Param(如feign.Param)。将所有@RequestParam更改为org.springframework.web.bind.annotation.RequestParam可以为我解决。

我不知道为什么会这样,但是Feign的存储库中有一个相关的question可能会解释一下。

相关问题