博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Spring Transaction Configuration.

Posted on 2013-12-09 11:02  钟悍  阅读(405)  评论(0编辑  收藏  举报
<?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-3.1.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

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

    <tx:advice id="test-repeatedReadTxAdvice" transaction-manager="test-txManager">
        <!-- the transactional semantics... -->
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" isolation="REPEATABLE_READ" rollback-for="Throwable" />
        </tx:attributes>
    </tx:advice>

    <tx:advice id="test-readCommitedTxAdvice" transaction-manager="test-txManager">
        <!-- the transactional semantics... -->
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Throwable" />
        </tx:attributes>
    </tx:advice>

    <tx:advice id="test-readCommitedTxAdvice-REQUIRES_NEW" transaction-manager="test-txManager">
        <!-- the transactional semantics... -->
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" rollback-for="Throwable" />
        </tx:attributes>
    </tx:advice>

    <aop:config>
        <aop:advisor pointcut="execution(* com.karl.test.TransactionService.*(..))" advice-ref="test-repeatedReadTxAdvice" />
    </aop:config>

</beans>