spring4声明式事务—02 xml配置方式
来源:互联网 发布:域名映射ip和端口 编辑:程序博客网 时间:2024/05/17 02:52
1.配置普通的 controller,service ,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 指定强制回滚之前事务可以占用的时间
0 0
- spring4声明式事务—02 xml配置方式
- spring4声明式事务—02 xml配置方式
- spring4声明式事务--01注解方式
- Spring配置声明式事务--xml配置文件方式
- Spring4深入理解----事务(声明式事务和xml配置事务,事务传播属性,事务其他属性(隔离级别&回滚&只读&过期))
- Spring4深入理解----事务(声明式事务和xml配置事务,事务传播属性,事务其他属性(隔离级别&回滚&只读&过期))
- spring4 之 声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring事务管理——使用XML配置声明式事务
- Spring声明式事务XML配置
- Spring声明式事务配置——AOP方式
- spring配置声明式事务--注解方式
- Spring配置声明式事务--注解方式
- Spring声明式事务的配置方式
- Spring4学习笔记-声明式事务(基于注解的方式)
- Spring4学习笔记-声明式事务(基于配置文件的方式)
- 设配器模式不止是补救,有时更像是一个创造者
- spring4声明式事务--01注解方式
- Objective-C里调用Swift
- Halcon算子--区域特征
- Powershell之MOF后门
- spring4声明式事务—02 xml配置方式
- 一些简单的操作符重载
- 责任链的方法化
- android 获取当前显示页面app 包名
- iOS 调用系统相机和相册
- openwrt之wifi驱动显示连接设备MAC
- cmd-bat批处理命令延时方法
- 观察者的前世今生
- 关于U秘开发的一些经验教训