spring cloud关于feign client的调用对象列表参数、设置header参数、多环境动态参数试配

spring cloud关于feign client的调用

     1、有些场景接口参数需要传对象列表参数

     2、有些场景接口设置设置权限等约定header参数

     3、有些场景虽然用的是feign调用,但并不会走eureka,比如调用外网www.baidu.com等的接口,需要进行多环境试配

示例如下:

      server controller端:

@RequestMapping(value = "bbbb", method = {RequestMethod.GET, RequestMethod.POST}, produces = "application/json;charset=UTF-8")
RespData<List<XxxxVo>> getConverseShortUrlForRobotBatch( @RequestParam("vId") Long vId,
@RequestBody List<XxxxVo> xxxxVoList,
HttpServletRequest httpServletRequest){
...........
List<XxxxVo> resultVoList = new ArrayList<XxxxVo>();
if(StringUtils.isNotEmpty(httpServletRequest.getHeader("token")) && httpServletRequest.getHeader("token").equals("xxxxx")){
..................
}
}

     client端(其中xxxx.business.service.domain,可以在properties配置文件里配置):

@FeignClient(name = "xxxxx-business-service", url = "http://${xxxx.business.service.domain}")
public interface ImptClient {
@RequestMapping(value = "/xxx/xxx/bbbbb", method = {RequestMethod.POST}, produces = "application/json;charset=UTF-8",headers = {"token=xxxxx"})
RespData<List<XxxxVo>> bbbbb(@RequestParam("vId") Long vId,@RequestBody List<XxxxVo> xxxxVoList);
}
posted @ 2019-08-02 17:05  xuzhujack  阅读(4187)  评论(0编辑  收藏  举报
;