spring设置隔离事务属性


设置隔离事务属性	
	isolation="DEFAULT" 默认的隔离级别
	DEFAULT  使用数据库本身的隔离级别 ORACLE(读已提交) MYSQL(可重复读-----解决了脏读和不可重复读的问题)
	READ_UNCOMMITTED  spring实现读未提交 (出现脏读)
	READ_COMMITTED     spring实现读已提交 (不可重复读+幻读待解决)
	REPEATABLE_READ   spring实现可重复读 (幻读待解决)
	SERIALIZABLE     spring实现串行化(已解决)


例:

<tx:attributes>
	<tx:method name="Update*" propagation="REQUIRED" isolation="DEFAULT" />
</tx:attributes>




<?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:context="http://www.springframework.org/schema/context"
	    xmlns:tx="http://www.springframework.org/schema/tx"
	    xmlns:aop="http://www.springframework.org/schema/aop"
	    xsi:schemaLocation="
	    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
	    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
	    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
	    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
    ">
    
    
    <!-- 扫描注解 -->
	<context:component-scan base-package="lesson04.testm"></context:component-scan>
	<!-- 读取properties资源文件 -->
	<context:property-placeholder location="classpath:/lesson04/jdbc/jdbcoracle.properties"/>
	
	
	<!-- ${username}是个关键字  默认获取操作系统用户 -->
	<!-- 连接数据库 -->
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="url" value="${url}"></property>
		<property name="username" value="${username1}"></property>
		<property name="password" value="${password}"></property>
		<property name="driverClassName" value="${driverClass}"></property>
	</bean>
	<!-- jdbc的模板   可以执行sql语句 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<!-- 把连接数据库的bean注入 -->
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	
	<!-- 事务管理类 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<!-- 事务需要操作数据库     要把连接数据库的bean注入 -->
		<property name="dataSource" ref="dataSource"></property>
	</bean>
	<!-- 定义通知  通知的代码  spring已经实现 -->
	<!-- 上面的id名为 id="transactionManager" 下面的 transaction-manager="transactionManager"可以不写-->
	<tx:advice id="myAdvise" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- 
			 	设置隔离事务属性	
	 			isolation="DEFAULT" 隔离级别
		   	       DEFAULT  使用数据库本身的隔离级别 ORACLE(读已提交) MYSQL(可重复读)
				   READ_UNCOMMITTED  spring实现读未提交 (脏读)
				   READ_COMMITTED     spring实现读已提交 (待解决--不可重复读+幻读)
				   REPEATABLE_READ   spring实现可重复读 (待解决--幻读)
				   SERIALIZABLE     spring实现串行化(已解决)
			 -->
			<tx:method name="Update*" propagation="REQUIRED" rollback-for="Exception" isolation="DEFAULT"/>
			<tx:method name="save*" propagation="REQUIRED"/>
			<tx:method name="delete*"/>
			<tx:method name="*" read-only="true"/>
		</tx:attributes>
	</tx:advice>
	
	<!-- 定义切点 -->
	<aop:config>
							<!-- 任意返回值    lesson04.testm.dao包下的所有类、所有方法拦截 -->
		<aop:pointcut expression="execution(* lesson04.testm.dao.*.*(..))" id="myPoint"/>
		<!-- 把切点和通知绑定     <tx:advice> -->
		<aop:advisor advice-ref="myAdvise" pointcut-ref="myPoint"/>
	</aop:config>
</beans>
	



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值