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);
}

相关文章:

  • 2022-01-15
  • 2022-12-23
  • 2021-05-14
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
猜你喜欢
  • 2022-02-22
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-21
  • 2022-01-17
  • 2022-12-23
相关资源
相似解决方案