aspect获取不到ServletRequestAttributes中的request
最近在用aop监听项目中restapi被调用的功能,在使用
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
的时候一只报attributes为null,
后来在web.xml中加入如下监听:
<!--将Web容器与spring容器进行整合-->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
就正常了。原因可能跟spring框架有关(个人猜测:spring将参数转化后params后,自动清理了servlet,所以要在xml中重新加入RequestContextListener)