日期:2014-05-16  浏览次数:20419 次

Spring声明式事务配置管理方法

事务配置

  • 首先在/WEB-INF/applicationContext.xml添加以下内容:
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

   <property name="sessionFactory">

       <ref bean="mySessionFactory"/>

   </property>

</bean>

注:这是作为公共使用的事务管理器Bean。这个会是事先配置好的,不需各个模块各自去配。

  • 下面就开始配置各个模块所必须的部分,在各自的applicationContext-XXX-beans.xml配置的对于事务管理的详细信息。

首先就是配置事务的传播特性,如下:

<!--  配置事务传播特性 -->
<tx:advice id="TestAdvice" transaction-manager