美文网首页
Spring MVC 事务配置

Spring MVC 事务配置

作者: Abel_橙汁 | 来源:发表于2017-08-24 17:18 被阅读0次

'''

<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="tourDataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />

<bean
    class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <!-- 指定满足哪些bean自动生成业务代理 -->
    <property name="beanNames">
        <!-- 需要自动创建事务代理的bean -->
        <list>
            <value>*Service</value>
        </list>
        <!-- 其它需要自动创建事务代理的bean -->
    </property>
    <property name="interceptorNames">
        <list>
            <value>transactionInterceptor</value>
            <!-- 可增加其它的interceptor -->
        </list>
    </property>
</bean>

<!-- 配置事务拦截器Bean -->
<bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <!-- 为事务拦截器bean注入一个事物管理器 -->
    <property name="transactionManager" ref="transactionManager"></property>
    <property name="transactionAttributes">
        <!-- 定义事务传播属性 -->
        <props>
            <prop key="insert*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="save*">PROPAGATION_REQUIRED</prop>
            <prop key="add*">PROPAGATION_REQUIRED</prop>
            <prop key="ConfirmUsed*">PROPAGATION_REQUIRED</prop>
            <prop key="edit*">PROPAGATION_REQUIRED</prop>
            <prop key="remove*">PROPAGATION_REQUIRED</prop>
            <prop key="delete*">PROPAGATION_REQUIRED</prop>
            <prop key="create*">PROPAGATION_REQUIRED</prop>
            <prop key="get*">PROPAGATION_REQUIRED</prop>
            <prop key="change*">PROPAGATION_REQUIRED</prop>
            <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
            <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
        </props>
    </property>
</bean>

'''

image.png

MySql 查看数据库引擎 show engines;

相关文章

网友评论

      本文标题:Spring MVC 事务配置

      本文链接:https://www.haomeiwen.com/subject/lyvedxtx.html