Spring声明式事务

来源:互联网 发布:个人网络研修计划 编辑:程序博客网 时间:2024/05/16 11:25

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <!-- Hibernate SessionFactory -->

    <bean id="workSessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="workDataSource" />
        </property>
        <property name="mappingResources">
            <list>
                <value>bss/model/work/AnswerSpec.hbm.xml</value>
                 -----
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.use_outer_join">true</prop>
                <prop key="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</prop>
                <prop key="hibernate.connection.pool_size">10</prop>
                <prop key="hibernate.jdbc.fetch_size">25</prop>
            </props>
        </property>
    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
  --用heibernate来管理事务 ,当用spring和heibernate一起完成DAO的时候 采用这个解决连接不是一个的问题
    <bean id="workTransaction" class="org.springframework.orm.hibernate.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="workSessionFactory" />
        </property>
    </bean>

   --具体限制那些方法要调用事务
    <bean id="txAttributes" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
        <property name="properties">
            <value>
                 storeComboOrderMsgAll=PROPAGATION_REQUIRED,-bss.common.BssException
                 insertBriefFlowIntefaceAll=PROPAGATION_REQUIRED,-bss.common.BssException
                 dispatchTfInas=PROPAGATION_REQUIRED,-bss.common.BssException
            </value>
        </property>
    </bean>
   
    <bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager">
            <ref bean="workTransaction" />
        </property>
        <property name="transactionAttributeSource">
            <ref bean="txAttributes" />
        </property>
    </bean>
    --制定事务的类 value是spring bean的id
    <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="interceptorNames">
            <value>txInterceptor</value>
        </property>
        <property name="beanNames">
            <list>
                <value>tacheManagerTarget</value>
                <value>interfaceManagerTarget</value>
            </list>
        </property>
    </bean>
   
</beans>

原创粉丝点击