0

I have to implement interceptor for logging via reflection in struts 1. Interceptors appeared in Struts 2 and there is no interceptors in struts 1, but there are some ways to implement such behaviour. I found 2 ways:

  1. Struts Action Invocation Framework (SAIF): http://struts.sourceforge.net/saif/#interceptor-class But there is very few information about it.

  2. AOP (aspects: org.aspectj)

What is the best way to solve this problem? Is there any other ways?

4

1 回答 1

0

编辑:对不起,我没有注意到这个问题有多老。

好吧,如果您不使用 Struts 1,我会为此推荐 Spring 框架。如果您想使用 Spring (3.2.9) 的(不是那么旧的)版本,它确实可以与 Struts 1 一起使用。当您使用它时,请查看 Spring MVC :)

Spring 具有出色的 AOP 支持,因为它的大部分“魔法”都是通过 AOP 执行的。

这是记录方法进入和退出的记录器的示例:

<aop:config>
    <aop:advisor advice-ref="loggingAdvisor"
        pointcut="execution(public * com.example.*(..))" />
</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>   
于 2014-07-03T02:21:08.617 回答