码迷,mamicode.com
首页 > 其他好文 > 详细

SSH2配置事务的两种方式

时间:2015-04-25 18:12:54      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

<?xml version="1.0" encoding="UTF-8"?>  

<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:context="http://www.springframework.org/schema/context"  

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  

        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  

        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  

<!-- 配置sessionFactory的方式 -->  

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  

<property name="configLocation">  

<value>classpath:config/hibernate.cfg.xml</value>  

</property>  

</bean>  

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  

<property name="sessionFactory" ref="sessionFactory"></property>  

</bean>  

<!-- 第一种配置事务的方式 ,tx-->  

    <!--    

<tx:advice id="txadvice" transaction-manager="transactionManager">  

<tx:attributes>  

<tx:method name="add*" propagation="REQUIRED" no-rollback-for="com.exception.MyRuntimeException"/>  

<tx:method name="modify*" propagation="REQUIRED" no-rollback-for="com.exception.MyRuntimeException"/>  

<tx:method name="del*" propagation="REQUIRED"/>  

<tx:method name="*" propagation="REQUIRED" read-only="true"/>  

</tx:attributes>  

</tx:advice>  

<aop:config>  

<aop:pointcut expression="execution(* com.dao.*.*(..))" id="daoMethod"/>  

<aop:advisor advice-ref="txadvice" pointcut-ref="daoMethod"/>  

</aop:config>  

    -->  

<!-- 第二种配置事务的方式,代理 -->  

<bean id="transactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">  

        <!-- 使用cglib方式实现动态代理  

<property name="proxyTargetClass" value="true"></property>  

         -->  

<property name="transactionManager" ref="transactionManager"></property>  

<property name="transactionAttributes">  

<props>  

<prop key="add*">PROPAGATION_REQUIRED, +RuntimeException</prop>  

<prop key="modify*">PROPAGATION_REQUIRED, +com.exception.MyRuntimeException</prop>  

<prop key="del*">PROPAGATION_REQUIRED</prop>  

<prop key="*">PROPAGATION_REQUIRED, readOnly</prop>  

</props>  

</property>  

</bean>  

<bean id="userDao" parent="transactionProxy">  

<property name="target">  

<!-- 直接写bean来代替ref标签的链接方式 -->  

<bean class="com.dao.impl.UserDaoImpl">  

<property name="sessionFactory" ref="sessionFactory"></property>  

</bean>              

</property>  

</bean>  

</beans

SSH2配置事务的两种方式

标签:

原文地址:http://www.cnblogs.com/luihengk/p/4456096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!