Spring學習筆記系列(六) aop

          實踐了《指南》中的例子165頁到169頁,最后補充一個Action,
          public class AOPMethodCostTimeAction extends ActionSupport {

           public ActionForward execute(ActionMapping mapping, ActionForm form,
             HttpServletRequest request, HttpServletResponse response)
             throws Exception {
            WebApplicationContext wac = this.getWebApplicationContext();
            ITest dao =(ITest)wac.getBean("myAOPProxyFactory");
            dao.doTest();
            dao.executeTest();
            return mapping.findForward("success");
           }

          }
          具體代碼已經放到gmail郵箱了。

          僅僅從這個例子總結一下:

          1,配置文件中需要
          <!-- aop test-->
           <bean id="myPointcutAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
            <property name="advice">
             <ref local="MyInterceptor"/>
            </property>
            <property name="patterns">
             <list>
              <value>.*do.*</value>
              <value>.*execute.*</value>
             </list>
            </property>
           </bean>
           <!-- user by PointcutAdvisor -->
           <bean id="MyInterceptor" class="srx.test.interceptor.MethodTimeCostInterceptor"></bean>
           <!-- proxy factory user by Actoin -->
           <bean id="myAOPProxyFactory" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="proxyInterfaces">
             <value>srx.test.interfaces.ITest</value>
            </property>
            <property name="target">
             <ref local="test"/>
            </property>
            <property name="interceptorNames">
             <value>myPointcutAdvisor</value>
            </property>
           </bean>
           <!-- the dao bean be proxyed-->
           <bean id="test" class="srx.test.impl.test"></bean>

           

           2,struts-config.xml

          <!-- AOP test , this is a action call two function ,and pring every method proced cost time-->
            <action path="/methodcost" type="srx.test.struts.action.AOPMethodCostTimeAction">
              <forward name="success" path="/WEB-INF/jsp/srx/test/aop/success.jsp"/>
            </action>

          使用動態代理,我本來有ITest接口,及其實現類test。以及使用test的Action?,F在,我想測試test

          種方法的調用時間,我需要怎么做呢?

          我只需要多定義三個Bean,myPointcutAdvisor,MyInterceptor,myAOPProxyFactory。

          三者的依賴關系

          myAOPProxyFactory [ myPointcutAdvisor MyInterceptor  ] ]

          其中advice定義和具體的Spring advice類有關系。

          待續。

          posted on 2007-06-18 18:03 chenguo 閱讀(161) 評論(0)  編輯  收藏 所屬分類: Spring Dev

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          留言簿

          隨筆分類(1)

          文章分類(52)

          好友 小山的博客

          最新隨筆

          最新評論

          主站蜘蛛池模板: 响水县| 康乐县| 顺昌县| 九江市| 诸暨市| 平顺县| 永城市| 依兰县| 江永县| 延川县| 前郭尔| 松阳县| 柘荣县| 永嘉县| 巫溪县| 团风县| 博兴县| 孝感市| 定西市| 墨竹工卡县| 登封市| 东安县| 会昌县| 永年县| 永胜县| 濉溪县| 马尔康县| 新密市| 漾濞| 威海市| 东乡| 新泰市| 康定县| 肥东县| 大化| 蓝山县| 临沧市| 姚安县| 循化| 冕宁县| 礼泉县|