我想在春季3使用方法拦截器来完成我的应用程序中的日志记录,以便我可以跟踪通过应用程序调用哪些方法。
是否有关于如何使用方法拦截器进行春季登录的教程(或建议)? 这似乎是已经做过很多次的事情,但是我还没有找到很多关于它的数据。
答案 0 :(得分:2)
Spring引用在Spring AOP上有一个whole chapter,可以作为一个非常详细的指南来完成你正在寻找的东西。试试看,如果你有更具体的问题,请问。
答案 1 :(得分:2)
Spring的 org.springframework.aop.interceptor.CustomizableTraceInterceptor 可让您实现此功能。
您可以自定义拦截器以记录方法的参数和返回值。
实施例: -
<aop:config>
<aop:advisor advice-ref="loggingAdvisor"
pointcut="execution(public * com.x.y.z.AbstractCommand.*(..))" />
</aop:config>
<bean id="loggingAdvisor"
class="org.springframework.aop.interceptor.CustomizableTraceInterceptor">
<property name="loggerName" value="logger-name" />
<property name="enterMessage" value="Entering $[methodName]($[arguments])" />
<property name="exitMessage" value="Leaving $[methodName](): $[returnValue]" />
</bean>