`
zenggang2008
  • 浏览: 29790 次
  • 性别: Icon_minigender_1
  • 来自: 南昌
社区版块
存档分类
最新评论

spring2.5配置声明式事务管理需小心!!

    博客分类:
  • java
阅读更多
  今天没事把原来项目里的spring换成了spring2.5,这下可好,项目出大漏子了
花点时间解决了,老鸟就不要看了,主要给新手提个醒~~~

第一个就是引入命名空间的那段配置不同了
<beans
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	[color=red]http://www.springframework.org/schema/aop[/color]
	http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
	[color=red]http://www.springframework.org/schema/tx[/color]
	http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

注意红色部分,少了就是不行~~~~~~~~~,这个郁闷了好久
第二个就是注意配置TransactionManager这个bean,如果是jdbc方式的话
	<bean id="txManage2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>

就ok了,不过你整合和hibernate的话,可要小心了,如果你还是按照上面这个配置的话呢
像readOnly这样的属性会依然起效,但是,这也是最麻痹人的地方,这样直接就导致了异常
不回滚!!!

所以,有了hibernate之后应该使用
	<bean id="txManage" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory"/>
	</bean>

这样的话,一切又和谐了~~~
分享到:
评论
2 楼 zenggang2008 2009-02-27  
besterzhao 写道

我就是使用DataSourceTransactionManager,出现了异常也不回滚,有什么办法让他自动回滚?最好是这个管理器能实现自动回滚

你用了hibernate吗?
1 楼 besterzhao 2009-02-27  
我就是使用DataSourceTransactionManager,出现了异常也不回滚,有什么办法让他自动回滚?最好是这个管理器能实现自动回滚

相关推荐

Global site tag (gtag.js) - Google Analytics