Spring事务管理(xml配置)

1.导入jar包
Spring事务管理(xml配置)_第1张图片
2.导入新的约束(tx)
Spring事务管理(xml配置)_第2张图片
beans:最基本
context:读取properties配置文件
aop:配置aop
tx:配置事务通知

3.配置通知

	
	<tx:advice transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="transfer" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
		tx:attributes>
	tx:advice>

如果有上百个属性,要一一配置事务的属性很麻烦,那么通过以下方法:
设置通配符,比如包含save的方法,一律使用

isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"

Spring事务管理(xml配置)_第3张图片
4.将通知织入目标

	
	<aop:config>
		<aop:pointcut expression="execution(*cn.service.*ServiceImpl.*(..))" id="txPc"/>
		
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/>
	aop:config>

配置完成后,会自动配置的切点表达式execution(*cn.service.ServiceImpl.(…))寻找符合条件的对象,织入通知,织入通知后会根据通知的关键字来判断具体需要哪些配置的属性

你可能感兴趣的:(技术,spring)