论坛首页 Java企业应用论坛

Spring Aop with struts Action

浏览 4555 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-07-17  
现在的项目中,想利用spring的AOP进行稍细粒度的权控制,配置如下:

代码:

<bean id="ruleAop" 
          class="org.springframework.aop.framework.ProxyFactoryBean"> 
          <property name="proxyInterfaces"> 
            <value>com.parenting.service.struts.IAction</value> 
          </property> 
          <property name="target"> 
              <idref bean="smstoicAction"/> 
          </property> 
          <property name="interceptorNames"> 
            <list> 
              <value>theAdvisor</value> 
            </list> 
          </property> 
        </bean> 

<!--Struts 的action交由spring的容器来管理(if using structs mvc);--> 
        <bean id="smstoicAction" name="/smstopic" class="com.parenting.service.struts.action.SmstopicAction" singleton="false"> 
          <property name="parentingService"> 
                  <ref bean="parentingServiceTarget"/> 
          </property> 
          <property name="smstopic"> 
            <ref local="smstopic" /> 
          </property> 
        </bean> 
        <!-- formbean --> 
        <bean id="smstopic" class="com.parenting.domain.model.pojo.Smstopic"></bean> 

        <!--ADVISOR--> 
        <!--Note: An advisor assembles pointcut and advice--> 
        <bean id="theAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"> 
          <property name="advice"> 
            <ref local="theBeforeAdvice"/> 
          </property> 
          <property name="patterns"> 
            <list> 
              <value>com\.parenting\.service\.struts\.IAction\.onSubmit_ADD</value> 
              <value>com\.parenting\.service\.struts\.IAction\.onSubmit_LOAD</value> 
              <value>com\.parenting\.service\.struts\.IAction\.onSubmit_LIST</value> 
              <value>com\.parenting\.service\.struts\.IAction\.onSubmit_DEL</value> 
              <value>com\.parenting\.service\.struts\.IAction\.onSubmit_UPDATE</value> 
            </list> 
          </property> 
        </bean> 

        <!--ADVICE处理逻辑--> 
        <bean id="theBeforeAdvice" class="com.parenting.test.TestBeforeAdvice"/> 
 

问题如下:当我调用smstopic.do的时候,没有触发AOP拦截.看了debug信息,好像是在调用SmstopicAction类的时候,并没通过代理创建实例,于是做如下测试:
代码:
try{ 
            ((com.parenting.service.struts.IAction); BeanManagerImpl.getBean("ruleAop");); 
                    .onSubmit_ADD(actionMapping, actionForm, httpServletRequest, 
                                httpServletResponse);; 
        }catch(Exception e);{ 
            e.printStackTrace();; 
        } 
 

运行,拦截成功.看了DEBUG信息,这时候的调用是走了factory代理出来的实例,所以拦截成功.

不知道大家有好的方法吗?
   发表时间:2005-07-19  
autoProxyCreator
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics