问题:在RequestInterceptor.apply
, RequestContextHolder.getRequestAttributes()为
null
, SecurityContextHolder.getContext().getAuthentication()也为null
解决方案:
方案1:在升级到Spring-Cloud Brixton之前,这个过去常常会起作用,因为现在hystrix命令可能在单独的线程中运行,因为更改为以下参数可以解决问题:
hystrix.command.default.execution.isolation.strategy: SEMAPHORE
方案2:对于Spring Boot 2+ / Spring Cloud Finchley +,如果您只需要安全上下文,则可以设置以下属性:
hystrix.shareSecurityContext=true
这样请求拦截器应该可以工作了。