首页 > 编程语言 > 详细

Spring 事务

时间:2016-02-18 15:08:42      阅读:250      评论:0      收藏:0      [点我收藏+]

1.利用Bean继承的方式 :Spring 事务的配置如下:


    txProxyTemplate的abstract="true",说明此类是一个抽象类,也可以不设置abstract属性,设置lazy-init="true"

也是把他当作抽象类,因为应用使用的是他的子bean,没必要的到代理类的实例。

    transactionManager是为事务代理bean注入使用适用于Hibernte的事务管理器

<beans>
    <!-- on spring context starting up, frech the application context -->
    <bean id="beansUtil" class="com.krm.util.BeansUtil"></bean>
    <!-- Transaction template for Managers, from: http://blog.exis.com/colin/archives/2004/07/31/concise-transaction-definitions-spring-11/ -->
    <bean id="txProxyTemplate" abstract="true"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager" ref="transactionManager" />
        <property name="transactionAttributes">
            <props>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="dataCollect">PROPAGATION_REQUIRED</prop>
                <prop key="getData*">PROPAGATION_REQUIRED</prop>
                <prop key="add*">PROPAGATION_REQUIRED</prop>
                <prop key="sort*">PROPAGATION_REQUIRED</prop>
                <prop key="del*">PROPAGATION_REQUIRED</prop>
                <prop key="set*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
                <prop key="forward*">PROPAGATION_REQUIRED</prop>
                <prop key="reject*">PROPAGATION_REQUIRED</prop>
                <prop key="recover*">PROPAGATION_REQUIRED</prop>
                <prop key="recycle*">PROPAGATION_REQUIRED</prop>
                <prop key="freeze*">PROPAGATION_REQUIRED</prop>
                <prop key="transfer*">PROPAGATION_REQUIRED</prop>
                <prop key="change*">PROPAGATION_REQUIRED</prop>
                <prop key="build*">PROPAGATION_REQUIRED</prop>
                <prop key="insert*">PROPAGATION_REQUIRED</prop>
                <prop key="*WithLog">PROPAGATION_REQUIRED</prop>
                <prop key="prepare*">PROPAGATION_REQUIRED</prop>
                <prop key="init*">PROPAGATION_REQUIRED</prop>
                <prop key="import*">PROPAGATION_REQUIRED</prop>
                <prop key="fill*">PROPAGATION_REQUIRED</prop>
                <prop key="restore*">PROPAGATION_REQUIRED</prop>
                <prop key="oper*">PROPAGATION_REQUIRED</prop>
                <prop key="batch*">PROPAGATION_REQUIRED</prop>
                <prop key="need*">PROPAGATION_REQUIRED</prop>
                <!--<prop key="get*">PROPAGATION_REQUIRED</prop> -->
                <prop key="copy*">PROPAGATION_REQUIRED</prop>
                <prop key="extractive*">PROPAGATION_REQUIRED</prop>
                <prop key="getNeedCarryInfo">PROPAGATION_REQUIRED</prop>
                <prop key="parseAndCompareItem">PROPAGATION_REQUIRED</prop>
                <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
            </props>
        </property>
    </bean>

    <!-- Generic manager that can be used to do basic CRUD operations on any 
        objects -->
    <bean id="uploadService" parent="txProxyTemplate">
        <property name="target">
            <bean class="com.krm.slsint.common.services.impl.UploadServiceImpl">
                <property name="uploadDAO" ref="uploadDAO" />
            </bean>
        </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative 
        to JTA) -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>

2.如果不使用继承的方式,则还需要配置目标范围,并且去掉abstract="true"属性

    <!--   为事务代理bean设置目标bean -->    
    <property name="target">    
        <!--   采用嵌套bean配置目标bean-->    
        <bean class="test.dao.impl.TaoTemplatesDAOImpl">    
            <property name="sessionFactory">    
                <ref local="sessionFactory" />    
            </property>    
        </bean>    
    </property> 

 

Spring 事务

原文:http://www.cnblogs.com/hehongtao/p/5198216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!