[spring cloud] feign声明

feign声明@PathVariable

@FeignClient(name = "TUZI")
public interface TuziClientService{
    @GetMapping("/demo/get/{id}")
    Tuzi get(@PathVariable(value="id") int id);//value需要显式声明,否则报错
}

@PathVariable必须要显示声明value

feign 返回InputStream

@FeignClient(contextId = "remoteDemoService", name = ItepServiceConstants.SERVICE_NAME, path = "demo"
//    ,configuration = RemoteDemoService.ClientConfiguration.class
)
public interface RemoteDemoService {
    @GetMapping("getById")
    ApiResult<demo> getById(String id);


    @GetMapping(value = "download")
    ApiResult download()
        throws IOException;

    class ClientConfiguration {

        @Autowired
        private ObjectFactory<httpmessageconverters> messageConverters;

        @Bean
        public Decoder feignDecoder () {
            return new Decoder() {
                @Override
                public Object decode(Response response, Type type)
                    throws IOException, DecodeException, FeignException {
                    return response.body().asInputStream();
                }
            };
        }
    }
}
```</httpmessageconverters></demo>
posted @ 2021-11-05 09:22  fight139  阅读(51)  评论(0编辑  收藏  举报