Spring框架(管理事务)

Spring底层使用Transaction事物模板来进行操作。具体操作:

1.service 需要获得 TransactionTemplate

2.spring 配置模板,并注入给service

3.模板需要注入事务管理器

4.配置事务管理器:DataSourceTransactionManager ,需要注入DataSource

了解底层即可,实际开发都是通过aop来配置事务的。


  • 手动管理模板

(1)修改Service

扫描二维码关注公众号,回复: 5263041 查看本文章

(2)修改Spring的配置文件

加上这句(导入配置文件):

<context:property-placeholder location="classpath:db.properties"/>


  • 通过工厂bean生成代理

Spring提供管理事务的代理工厂bean:TransactionProxyFactoryBean

(1)修改Spring的配置文件


  • 常用:基于AOP的事务配置(xml方式)

(1)Spring的配置文件


  • 常用:基于AOP的事务配置(注解方式)

猜你喜欢

转载自www.cnblogs.com/chichung/p/10416126.html