Spring声明式事务(xml配置事务方式)

Spring声明式事务(xml配置事务方式)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

蕃薯耀 2016年5月24日 10:12:13 星期二

http://fanshuyao.iteye.com/

xlm配置如下:

<!-- 启用事务注解 -->
	<!-- 
		Spring事务默认只能对运行时异常(RuntimeException)进行回滚,
		不会对Exception进行回滚。
		如果需要指定其他异常,则需要配置:rollbackFor=Exception.class
	 -->
	 <!-- 注解事务 -->
	<!-- <tx:annotation-driven transaction-manager="transactionManager"/> -->
	
	<!-- xml配置事务属性 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="get*" read-only="true" isolation="READ_COMMITTED"/>
			<tx:method name="query*" read-only="true" isolation="READ_COMMITTED"/>
			<!-- <tx:method name="find*" read-only="true" isolation="READ_COMMITTED"/> -->
			<!-- <tx:method name="search*" read-only="true" isolation="READ_COMMITTED"/> -->
			<!-- <tx:method name="list*" read-only="true" isolation="READ_COMMITTED"/> -->
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>
	
	
	<aop:config>
		<!-- 配置事务切点 -->
		<aop:pointcut expression="execution(* com.lqy.spring.iwx.service.*.*(..))" id="txPointcut"/>
		
		<!-- 关联事务属性及切点 -->
		<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
	</aop:config>

注意:

当事务切点配置成这样时:

<!-- 配置事务切点 -->
<aop:pointcut expression="execution(* com.lqy.spring.iwx.service.impl.*(..))" id="txPointcut"/>

 即expression中红色标记的地方

expression="execution(* com.lqy.spring.iwx.service.impl.*(..))",

配置成这样的话,就会在此处报错:

<!-- 关联事务属性及切点 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/

Pointcut is malformed: warning no match for this type name: com.lqy.spring.iwx.service.impl [Xlint:invalidAbsoluteTypeName]

如果把红色的impl配置成 * ,则没有报错,运行也正常。不知道是什么原因,暂时记录。

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.

蕃薯耀 2016年5月24日 10:12:13 星期二

http://fanshuyao.iteye.com/

猜你喜欢

转载自fanshuyao.iteye.com/blog/2300350