zoukankan      html  css  js  c++  java
  • SSH2配置事务的两种方式

    <?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

  • 相关阅读:
    使用phantomjs进行刷商务通对话
    利用python打造自己的ftp暴力破解工具
    notepad++开发中常用的插件
    织梦重装漏洞其实并不是那么好利用
    织梦开启调试模式
    网站安全开发人员不可缺少的火狐插件
    dos批量替换当前目录后缀名
    wpf 帧动画
    C 语言 mmap
    C 语言 ioctl
  • 原文地址:https://www.cnblogs.com/luihengk/p/4456096.html
Copyright © 2011-2022 走看看