HTTP 请求的 Spring AOP 日志记录



我正在尝试通过aop在控制器中记录http请求。但是,在方面代码中,如果我

    httpServletRequest.getInputStream()

然后,请求数据将无法在主流中检索。

因此,我在控制器中使用了另一个公共方法,该方法传入请求字符串

    public String processRequest(String data){...}

这种方法是记录"数据"的切入点。

但问题是,似乎这种方法的切入点无法通过 Spring 识别,这种方法没有日志记录。我需要这方面的帮助。

这是 aop 的定义

     <bean id="myLogger" class="com.my.MyLogger" />
<aop:config>
    <aop:aspect id="Log" ref="myLogger">
        <aop:around  method="log" pointcut="execution(public * com.my.controller.processRequest(..))" />
    </aop:aspect>
</aop:config>
Spring AOP

默认使用AOP代理。因此,您的原始 Bean 被生成的代理 Bean 包装,所有"外部"调用都通过代理。内部方法调用(在同一 Bean 中)绕过代理。

这里解释得很好:http://static.springsource.org/spring/docs/2.5.5/reference/aop.html#aop-understanding-aop-proxies

最新更新