閑人野居
          好好學(xué)習(xí),天天向上
          posts - 57,  comments - 137,  trackbacks - 0
          在spring2.0中,aop發(fā)生了很大的變化:
          主要分為兩大方面
          1.支持簡(jiǎn)單的aop xml配置
          2.支持@AspectJ的注釋

          先來(lái)看一看第一種情況:
          申明一個(gè)aspect,在xml中的申明如下:

          <aop:config>

          ? <aop:aspect id="myAspect" ref="aBean">

          ??? ...

          ? </aop:aspect>

          </aop:config>

          <bean id="aBean" class="...">

          ? ...

          </bean>


          申明pointcut

          <aop:config>

          ? <aop:pointcut id="businessService"

          ??????? expression="execution(* com.xyz.myapp.service.*.*(..))"/>

          </aop:config>


          申明advice

          Before advice

          <aop:aspect id="beforeExample" ref="aBean">

          ??? <aop:before

          ????? pointcut-ref="dataAccessOperation"

          ????? method="doAccessCheck"/>

          </aop:aspect>

          After returning advice:

          <aop:aspect id="afterReturningExample" ref="aBean">

          ?

          ??? <aop:after-returning

          ????? pointcut-ref="dataAccessOperation"

          ????? method="doAccessCheck"/>

          ?????????

          ??? ...

          ???

          </aop:aspect>

          或者帶有返回參數(shù)

          <aop:aspect id="afterReturningExample" ref="aBean">

          ?

          ??? <aop:after-returning

          ????? pointcut-ref="dataAccessOperation"

          ???? ?returning="retVal"

          ????? method="doAccessCheck"/>

          ?????????

          ??? ...

          ???

          </aop:aspect>

          ?

          After throwing advice

          <aop:aspect id="afterThrowingExample" ref="aBean">

          ?

          ??? <aop:after-throwing

          ????? pointcut-ref="dataAccessOperation"

          ????? method="doRecoveryActions"/>

          ?????????

          ??? ...

          ???

          </aop:aspect>

          或者帶有throwing

          <aop:aspect id="afterThrowingExample" ref="aBean">

          ?

          ??? <aop:after-throwing

          ????? pointcut-ref="dataAccessOperation"

          ????? throwing="dataAccessEx"

          ????? method="doRecoveryActions"/>

          ?????????

          ??? ...

          ???

          </aop:aspect>

          After (finally) advice

          <aop:aspect id="afterFinallyExample" ref="aBean">

          ?

          ??? <aop:after

          ????? pointcut-ref="dataAccessOperation"

          ????? method="doReleaseLock"/>

          ?????????

          ??? ...

          ???

          </aop:aspect>

          Around advice

          <aop:aspect id="aroundExample" ref="aBean">

          ?

          ??? <aop:around

          ????? pointcut-ref="businessService"

          ????? method="doBasicProfiling"/>

          ?????????

          ??? ...

          ???

          </aop:aspect>

          Advice parameters

          <aop:before

          ? pointcut="Pointcuts.anyPublicMethod() and @annotation(auditable)"

          ? method="audit"

          ??arg-names="auditable"/>


          對(duì)于引入接口(Introductions):

          <aop:aspect id="usageTrackerAspect" ref="usageTracking">

          ? <aop:declare-parents

          ????? types-matching="com.xzy.myapp.service.*+",

          ????? implement-interface="UsageTracked"
          ????? default-impl=" service.tracking.DefaultUsageTracked"/>

          ? <aop:before

          ??? pointcut="com.xyz.myapp.SystemArchitecture.businessService()

          ????????????? and this(usageTracked)"

          ??? method="recordUsage"/>

          </aop:aspect>

          ?
          posted on 2006-09-15 09:41 布衣郎 閱讀(1995) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): aopspring

          <2006年9月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          常用鏈接

          留言簿(12)

          隨筆分類(lèi)(59)

          隨筆檔案(57)

          blog

          java

          uml

          搜索

          •  

          積分與排名

          • 積分 - 358033
          • 排名 - 156

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 宁河县| 寿宁县| 桃园市| 南溪县| 那坡县| 望城县| 桂东县| 曲阳县| 两当县| 富裕县| 神木县| 石家庄市| 沾益县| 龙陵县| 兴海县| 杂多县| 易门县| 确山县| 来凤县| 鹰潭市| 松溪县| 阿城市| 栾城县| 灵川县| 陈巴尔虎旗| 长寿区| 平湖市| 阿克苏市| 扶风县| 繁昌县| 安泽县| 扶绥县| 化德县| 贵阳市| 襄垣县| 长汀县| 南充市| 元阳县| 铁岭县| 象山县| 上饶县|