<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-9  評論-168  文章-266  trackbacks-0

    一.AOP(常用)

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"

    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    <!-- 這是我們將要配置并使它具有事務性的Service對象 -->

    <bean id="fooService" class="x.y.service.DefaultFooService"/>

    <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) -->

    <tx:advice id="txAdvice" transaction-manager="txManager">
    <!-- the transactional semantics... -->

    <tx:attributes>
    <!-- all methods starting with 'get' are read-only -->

    <tx:method name="get*" read-only="true"/>
    <!-- other methods use the default transaction settings (see below) -->

    <tx:method name="*"/>
    </tx:attributes>
    </tx:advice>
    <!-- ensure that the above transactional advice runs for any executionof an operation defined by the FooService interface -->

    <aop:config>
    <aop:pointcut id="fooServiceOperation" expression="execution(* x.y.service.FooService.*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>
    </aop:config>
    <!-- ******************************************************************-->
    <!-- don't forget the DataSource -->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
    <property name="url" value="jdbc:oracle:thin:@rj-t42:1521:elvis"/>
    <property name="username" value="scott"/>
    <property name="password" value="tiger"/>
    </bean>

    <!-- similarly, don't forget the (particular) PlatformTransactionManager -->

    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- other <bean/> definitions here -->

    </beans>

    我們來分析一下上面的配置。我們要把一個服務對象('fooService' bean)做成事務性的。我們想施加的事務語義封裝在<tx:advice/>定義中。<tx:advice/>把所有以 'get' 開頭的方法看做執(zhí)行在只讀事務上下文中,其余的方法執(zhí)行在默認語義的事務上下文中”。 其中的 'transaction-manager' 屬性被設置為一個指向 PlatformTransactionManager bean的名字(這里指 'txManager'),該bean將實際上實施事務管理。

    配置中最后一段是 <aop:config/> 的定義,它確保由 'txAdvice' bean定義的事務通知在應用中合適的點被執(zhí)行。首先我們定義了 一個切面,它匹配 FooService 接口定義的所有操作,我們把該切面叫做 'fooServiceOperation'。然后我們用一個通知器(advisor)把這個切面與 'txAdvice' 綁定在一起,表示當 'fooServiceOperation' 執(zhí)行時,'txAdvice' 定義的通知邏輯將被執(zhí)行。

    一個普遍性的需求是讓整個服務層成為事務性的。滿足該需求的最好方式是讓切面表達式匹配服務層的所有操作方法。例如:

    <aop:config>
        <aop:pointcut id="fooServiceMethods" expression="execution(* x.y.service.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceMethods"/>
      </aop:config>
    posted on 2009-03-30 17:37 紫蝶∏飛揚↗ 閱讀(2494) 評論(0)  編輯  收藏 所屬分類: Spring
    主站蜘蛛池模板: 国产免费观看网站| 免费观看的av毛片的网站| 国产亚洲午夜高清国产拍精品| 亚洲精品无码国产片| 天天摸天天碰成人免费视频| 亚洲美国产亚洲AV| 日韩一级在线播放免费观看| 国产精品亚洲天堂| 无码专区一va亚洲v专区在线 | 久久免费高清视频| 亚洲av日韩av不卡在线观看| 在线观看永久免费| 67194在线午夜亚洲| 日本媚薬痉挛在线观看免费| 美女羞羞视频免费网站| a级亚洲片精品久久久久久久| 国产偷伦视频免费观看| 亚洲第一永久在线观看| 毛色毛片免费观看| 免费看一级一级人妻片| 精品亚洲综合久久中文字幕| 37pao成人国产永久免费视频| 亚洲男人天堂2018av| 国产一级大片免费看| 丝袜足液精子免费视频| 亚洲高清不卡视频| 日本免费一二区在线电影| 永久免费无码网站在线观看个| 久久精品亚洲中文字幕无码网站 | 韩国亚洲伊人久久综合影院| 久久精品亚洲乱码伦伦中文| 久久久久久精品免费免费自慰| 亚洲人成网亚洲欧洲无码| 中文字幕亚洲日韩无线码| 84pao强力永久免费高清| 蜜芽亚洲av无码一区二区三区| 亚洲五月综合缴情在线观看| 2021免费日韩视频网| av片在线观看永久免费| 中文字幕一区二区三区免费视频| 亚洲国产精品婷婷久久|