SpringMVC项目如何添加事物呢

很简单--在applicationContext下边添加如下配置即可

<!-- 添加事务管理器 -->
    <bean id="transactionManager"  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    
    
    <!-- 配置声明事务 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="add*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
    
    <aop:config>
        <aop:pointcut expression="execution(* com.www.service.UserService.*(..))" id="p1"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="p1"/>
    </aop:config>

posted on 2018-09-27 20:38  爪哇玛咖  阅读(270)  评论(0编辑  收藏  举报

导航