Spring 4宣言トランザクション-02 xml構成

9053 ワード

1.通常のコントローラ、サービス、daoのbeanを配置する.
<!--   dao ,service -->
    <bean id="bookShopDao" class="com.liujl.spring.tx.xml.BookShopDaoImpl">
        <property name="jdbcTemplate" ref="jdbcTemplate"></property>
    </bean>
    
    <bean id="bookShopService" class="com.liujl.spring.tx.xml.serivice.impl.BookShopServiceImpl">
        <property name="bookShopDao" ref="bookShopDao"></property>
    </bean>
    
    <bean id="cashier" class="com.liujl.spring.tx.xml.serivice.impl.CashierImpl">
        <property name="bookShopService" ref="bookShopService"></property>
    </bean>

2.トランザクションマネージャbeanの構成
<!--   hibernate、jpa  -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

3.txネーミングスペースの導入
xmlns:tx="http://www.springframework.org/schema/tx"

4.トランザクションの各プロパティの構成(メソッド名はワイルドカード*を使用できます)
<!--   -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="purchase" propagation="REQUIRED"/>
            <tx:method name="checkout" propagation="REQUIRED"/>
            <tx:method name="get*" read-only="true"/>            
            <tx:method name="find*" read-only="true"/>            
        </tx:attributes>
    </tx:advice>

5.aopネーミングスペースの導入
xmlns:aop="http://www.springframework.org/schema/aop"

6.トランザクションの接点を設定し、トランザクションの接点とトランザクション属性を関連付ける
<!--  ,  -->
    <aop:config>
        <aop:pointcut expression="execution(* com.liujl.spring.tx.xml.serivice.*.*(..))" id="txPointCut"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
    </aop:config>
  :  
    1.  propagation   ,  REQUIRED  , 
    REQUIRES_NEW  , ( )
    
    2.  isolation   ,  READ_COMMITTED  

    3. Spring     。
     , 。  noRollbackFor

    4.  readOnly   , ,
     。 , readOnly=true
    
    5.  timeout