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。現在,我想測試test

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

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

          三者的依賴關系

          myAOPProxyFactory [ myPointcutAdvisor MyInterceptor  ] ]

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

          待續。

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

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

          導航

          統計

          留言簿

          隨筆分類(1)

          文章分類(52)

          好友 小山的博客

          最新隨筆

          最新評論

          主站蜘蛛池模板: 牡丹江市| 城口县| 五华县| 伊宁县| 太保市| 富裕县| 上蔡县| 青神县| 班戈县| 靖江市| 长垣县| 桃源县| 辉县市| 开封县| 湖州市| 昌乐县| 运城市| 温泉县| 合川市| 噶尔县| 霍山县| 彭水| 内乡县| 怀宁县| 安西县| 汝州市| 阿拉尔市| 卢氏县| 赞皇县| 新余市| 金塔县| 大丰市| 修武县| 旬邑县| 芷江| 故城县| 沽源县| 浦江县| 桐城市| 闽侯县| 泰来县|