欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring 2.x声明式事务管理的配置示例

程序员文章站 2022-03-14 21:37:22
...
你这是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>

相关标签: 配置管理 Spring