当struts将action托管给spring后,,有个优点是可以将spring的AOP拦截器用于struts的动作
比如创建一个日志记录拦截器

import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

public class LoggingInterceptor implements MethodBeforeAdvice {

 public void before(Method method, Object[] objects, Object o)
   throws Throwable {
  System.out.println("logging before: " + o.getClass());
 }
}


  要使用该拦截器的话,需要在applicationContext.xml中定义该拦截器的对象,如
 

<!-- 配置拦截器 -->
 <bean name="logger" class="com.demo.spring.aop.LoggingInterceptor" />

 <!-- 配置拦截器代理 -->
 <bean name="loggingAutoProxy"
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames">
   <list>
    <value>/login</value>
    <value>/register</value>
   </list>
  </property>
  <property name="interceptorNames">
   <list>
    <value>logger</value>
   </list>
  </property>
 </bean>


  如果要拦截其它struts侗族,则只需要在beanNames下附加<value>标记增加相关的 strus动作即可,从而达到一个简单的spring aop
拦截器的目的

相关文章:

  • 2022-02-25
  • 2022-12-23
  • 2021-06-12
  • 2022-01-19
  • 2021-10-10
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2018-10-11
  • 2021-06-18
  • 2022-12-23
  • 2022-01-06
  • 2021-04-07
  • 2021-11-12
相关资源
相似解决方案