4

我们最近从版本 2.0.0 升级到spring-cloud-starter-openfeign: 2.2.2 ,在调用使用consumes并具有@RequestHeaderContent-Type 的 REST API 时遇到以下异常:

    feign.FeignException$UnsupportedMediaType: [415] during [POST] to [http://localhost:8080/test]
    [TestFeign#test(TestRequest,String)]: [{"timestamp":"2021-01-03T13:13:58.192+0000",
    "status":415,"error":"Unsupported Media Type",
    "message":"Invalid mime type \"application/json, application/json\": 
    Invalid token character ',' in token \"json, application/json\"","path":"/test"}] 

我们的 Feign 接口定义如下:
@RequestMapping(value = "/test",method = RequestMethod.POST,consumes= {"application/json"},
produces={"application/json"})
void test(@RequestBody TestRequest request,@RequestHeader("Content-Type") String contentType); 

我们调查并看到在这种情况下,两个值都被连接如下:

Content-Type: "application/json, application/json"

使用时spring-cloud-starter-openfeign:2.0.0不会出现此问题。

4

0 回答 0