spring配置事务处理,选择annotation驱动的方式.
1.在配置文件中加入schema.
xmlns:tx="http://www.springframework.org/schema/tx" http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
2.声明事务管理器
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
3.在Service中声明事务:@Transactional.
据说这是最佳方法.俺配上去用了,没什么地方报异常,但也不知道是不是就成功了?呵呵..得测试一下.