我愛熊貓

          最新評論

          spring aop 之二 xml方式

          前篇介紹的是使用注釋方式實現(xiàn)aop,本篇將介紹使用xml方式實現(xiàn)。

          先看xml的配置:

          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
          http://www.springframework.org/schema/aop

          <bean id="helloService" class="cn.com.ultrapower.service.HelloServiceImpl">
          </bean>
          <bean id="helloAction" class="cn.com.ultrapower.action.HelloActionImpl">
          <property name="helloService"><ref bean="helloService"/></property>
          <property name="name" value="yoo"></property>
          </bean>
          <bean id="logAdvisor" class="cn.com.ultrapower.advice.schemabased.LogAdvisor">
          </bean>
          <aop:config>
          <aop:aspect ref="logAdvisor">
          <aop:pointcut id="someMethod" expression="execution(* cn.com.ultrapower.action.IHelloAction.*(..))"/>
          <aop:after-returning pointcut-ref="someMethod" method="after"/>
          <aop:before pointcut-ref="someMethod" method="after"/>
          </aop:aspect>
          </aop:config>
          </beans>
          這里定義了兩個普通的bean:helloService和helloAction。另外定義了一個用于監(jiān)聽的logAdvisor。

          特殊的是<aop:config>...</aop:config>中的監(jiān)聽器配置。定義了切面,切點,前置方法和后置方法。

          然后再看看logAdvisor的代碼:

          public class LogAdvisor {

          public void before() {
          System.out.println("Log:before method!");
          }

          public void after() {
          System.out.println("Log:after method!");
          }
          }

          很簡單,就兩個普通方法,before用于前置打印信息,after用于后置打印信息。

          posted on 2008-06-07 20:54 flyoo 閱讀(80) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 临湘市| 临高县| 呈贡县| 阿拉善右旗| 泰州市| 德兴市| 广德县| 班戈县| 顺平县| 凤阳县| 安丘市| 德兴市| 思茅市| 康乐县| 广宁县| 澎湖县| 商都县| 台湾省| 遵化市| 长武县| 社旗县| 封丘县| 榆树市| 游戏| 珠海市| 武穴市| 富顺县| 神池县| 涟源市| 朔州市| 泸溪县| 民乐县| 桦甸市| 连平县| 青川县| 唐河县| 那坡县| 宣恩县| 会同县| 凯里市| 大邑县|