<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' 開頭的方法看做執行在只讀事務上下文中,其余的方法執行在默認語義的事務上下文中”。 其中的 'transaction-manager' 屬性被設置為一個指向 PlatformTransactionManager bean的名字(這里指 'txManager'),該bean將實際上實施事務管理。

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

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

    <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
    主站蜘蛛池模板: 成年女人毛片免费观看97| 一区二区三区免费视频播放器| 亚洲成A∨人片在线观看无码| 无码乱人伦一区二区亚洲| 亚洲va无码手机在线电影| 亚洲国产国产综合一区首页| 亚洲AV无码AV男人的天堂| 亚洲天天在线日亚洲洲精| 亚洲无线电影官网| 亚洲经典在线中文字幕| 亚洲精品国产成人| 国产91在线|亚洲| 亚洲国产欧洲综合997久久| 无码天堂亚洲国产AV| 污网站在线观看免费| 最近的2019免费中文字幕| 久久久久成人精品免费播放动漫| 日韩免费无码视频一区二区三区 | 亚洲香蕉网久久综合影视| 国产亚洲色视频在线| 国产aⅴ无码专区亚洲av| 久久99国产亚洲精品观看| 亚洲小视频在线播放| 亚洲妇女熟BBW| 美女扒开尿口给男人爽免费视频 | 美女免费精品高清毛片在线视| 无人视频在线观看免费播放影院| 在线免费视频你懂的| 三年片在线观看免费大全电影 | 一级毛片在线免费视频| 免费一区二区三区| 在线观看免费高清视频| 永久黄网站色视频免费观看| 亚洲熟伦熟女新五十路熟妇| 无码乱人伦一区二区亚洲一| 国产亚洲sss在线播放| 色爽黄1000部免费软件下载| 在线毛片片免费观看| 毛片a级毛片免费观看免下载| 亚洲AV无码一区二三区| 日韩亚洲Av人人夜夜澡人人爽|