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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM