spring 事务配置

<?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:p="http://www.springframework.org/schema/p"
  
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <!-- To define those things need to adopt management class -->
    <bean id="BeanProxy"
        class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
            <!-- 对bean名以Service结尾的类进行代理 -->
            <list>
                <value>*Service</value>
            </list>
        </property>
        <!-- The agent class is loaded Interceptor (realization notification procedure) -->
        <property name="interceptorNames">
            <list>
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>

    <!-- Define interceptor attribute is used to specify things, grade, exception handling         -->
    <bean id="transactionInterceptor"
        class="org.springframework.transaction.interceptor.TransactionInterceptor">
        <property name="transactionManager" ref="transactionManager"></property>
        <property name="transactionAttributes">
            <props>
  
              <!-- PROPAGATION_SUPPORTS: If a transaction already 
exists, then added to the transaction; if no transaction, places of 
implementation of non-transaction;
                     PROPAGATION_MANDATORY: Use the current transaction, if not, an exception is thrown;
                     PROPAGATION_REQUIRED: New Transaction, if you currently have a transaction, pending;
  
                   PROPAGATION_NOT_SUPPORTED: by way of non-execution of
 the transaction, if the transaction currently is pending;
          
           PROPAGATION_NEVER: by way of non-execution of the transaction
 if you currently have a transaction, an exception is thrown;
       
              +/- Exception: + indicates when something abnormal occurs 
submitted - represents an exception occurs when the transaction rollback
 -->
                <prop key="get*">PROPAGATION_SUPPORTS,readOnly,-Exception</prop>
                <prop key="query*">PROPAGATION_SUPPORTS,readOnly,-Exception</prop>
                <prop key="select*">PROPAGATION_SUPPORTS,readOnly,-Exception</prop>
                <prop key="del*"> PROPAGATION_SUPPORTS,-Exception</prop>
                <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="*find*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="submit**">PROPAGATION_REQUIRED,-Exception</prop>
            </props>
        </property>
    </bean>

    <!-- By the spring of transaction management mybatis -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
</beans>


转载于:https://my.oschina.net/sky8wolf/blog/621638

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值