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