问题描述在实际访问API时,是POST的方式;问题出现的环境背景及自己尝试过哪些方法相关代码// 请把代码文本粘贴到下方(请勿用图片代替代码)@RequestMapping(value = "/permission/current",method = RequestMethod.GET )@Headers({"Content-Type: application/json","Authorization:{token}"})
Map<String,Object> getPermission(@Param("token") String token);你期待的结果是什么?实际看到的错误信息又是什么?怎么修改才可以支持Headers Authorization token,或者是 Springcloud Fegin 在此不支持?
1 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
you can add a Interceptor, put token to header, then you do not have to send token as a param for all the function .
public class FeignBasicAuthRequestInterceptor implements RequestInterceptor { public FeignBasicAuthRequestInterceptor() { } @Override public void apply(RequestTemplate template) { HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest(); String token = (String)request.getSession().getAttribute("Authorization"); template.header("Authorization", token); } }
@Configurationpublic class FeignConfiguration { /** * 创建Feign请求拦截器,在发送请求前设置认证的token,各个微服务将token设置到环境变量中来达到通用 * @return */ @Bean public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new FeignBasicAuthRequestInterceptor(); } /** * feigin 日志配置 * * @return */ @Bean public Logger.Level feignLoggerLevel() { return feign.Logger.Level.FULL; } }
- 1 回答
- 0 关注
- 1700 浏览
添加回答
举报
0/150
提交
取消