Spring

1.基于xml配置事务

<!-- 配置 Spring 的声明式事务 -->
    <!-- 1. 配置事务管理器 -->
    <bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager" id="transactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 2. 配置事务通知 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <!-- propagation 事务传播,默认REQUIRED,这是一个具有事务的方法,没有则创建事务-->
            <!-- isolation 事务隔离,默认DEFAULT,此设置是为了解决并发事务中,脏读、不可重复读外、幻读,性能会下降-->
            <tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT" />
            <tx:method name="delete*" />
            <tx:method name="udate*" />
            <!--只读事务,只做查询,不修改数据的事务。JDBC驱动会进行优化-->
            <tx:method name="*" read-only="true" />
            <tx:method name="find*" read-only="true"  />
            <tx:method name="get*" read-only="true" />
        </tx:attributes>
    </tx:advice>

    <!-- 事务切点  并把切点和事务属性关联起来-->
    <aop:config>
        <aop:pointcut id="pointcut" expression="execution(* com.blog.service.*.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
    </aop:config>

   转载规则


《Spring》 yywzt 采用 知识共享署名 4.0 国际许可协议 进行许可。
 上一篇
SpringMVC SpringMVC
1.HiddenHttpMethodFilter、HttpPutFormContentFilterHiddenHttpMethodFilter 可以把 POST 请求转为 DELETE 或 POST 请求 可以把 POST 请求转为 DE
2018-06-23
本篇 
Spring Spring
1.基于xml配置事务<!-- 配置 Spring 的声明式事务 --> <!-- 1. 配置事务管理器 --> <bean class="org.springframework.jdbc.datasour
2018-06-23
  目录