---
title: "Spring 2.x声明式事务管理的配置示例"
author: "movingboy"
date: "2008-11-19T16:42:38Z"
tags: []
slug: "spring-2-x"
draft: false
lastmod: "2008-11-19T16:44:06Z"
id: 270589
url: "https://movingboy.iteye.com/blog/270589"
---

你这是Spring 1.x的配置。如果是用Spring 2.x，可以参考下面的配置：


```
<!--设置事务管理  -->      
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  <property name="sessionFactory">  
   <ref local="sessionFactory" />  
  </property>  
 </bean>   

	<!-- Transactional advice -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<!-- methods starting with 'save', 'update' or 'remove' use the default transaction settings -->
			<tx:method name="save*"/>
			<tx:method name="update*"/>
			<tx:method name="remove*"/>

			<!-- other methods are set to read only -->
			<tx:method name="*" read-only="true"/>
		</tx:attributes>
	</tx:advice>

	<!-- ensure that the above transactional advice runs for any execution
	of an operation defined by specified interface -->
	<aop:config>
		<aop:pointcut id="daoOperation"
			expression="execution(* com.DAO.BasicDAO.*(..))"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="daoOperation"/>
	</aop:config>

<bean id="BasicDAO" class="com.DAO.BasicDAO">  
    <property name="sessionFactory">  
        <ref local="sessionFactory" />  
    </property>  
</bean>

<bean name="/login" class="com.struts.LoginAction" singleton="false">  
    <property name="basicDAO">  
        <ref bean="BasicDAO" />  
    </property>  
</bean>
```