Spring声明式事务

事务的ACID原则:原子性、一致性、隔离性、持久性。

复制代码
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

<!-- 配置增强类 -->
<tx:advice id="transAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <!-- transfer方法进行事务 -->
        <tx:method name="transfer" propagation="REQUIRED" timeout="30" read-only="false" isolation="REPEATABLE_READ"/>
        <!-- 所有方法进行事务,传播行为默认REQUIRED,隔离级别默认RR、超时-1、是否只读默认false... -->
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>

<!-- aop配置 -->
<aop:config>
    <!-- 定义切入点 -->
    <aop:pointcut id="pt" expression="execution(* com.service.AccountService.transfer(..))"/>
    <!-- 将增强类注入到切入点上 -->
    <aop:advisor advice-ref="transAdvice" pointcut-ref="pt"/>
</aop:config>
复制代码

 

posted @   数星观月  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
点击右上角即可分享
微信分享提示