1、出现的问题
在使用feign 调用过程中出现了 java.lang.NullPointerException: null 空指针错误,
根据debug 信息可以看到是由 (ServletRequestAttributes)RequestContextHolder.getRequestAttributes()报出来的,可以看出主要是由RequestContextHolder 报出来的
估计很多人正常在使用过程中不会产生这种问题,都能正常请求到。
2、出现的问题的原因
原因是,正常情况下,我们都在controller方法内或者后调用fegin,而我这次是在filter 中就使用了fegin调用了远程接口,这个时候
RequestContextHolder中的RequestAttributes 还是空的,这里面是个ThreadLocal,下面是RequestContextHolder中的部分源码
private static final ThreadLocal<RequestAttributes> requestAttributesHolder =
new NamedThreadLocal<RequestAttributes>("Request attributes