其他分享
首页 > 其他分享> > Spring通过aop实现事务管理

Spring通过aop实现事务管理

作者:互联网

1.在resources目录下的spring-dao.xml中添加于事务有关的bean

 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
</bean>

2.配置事务通知

<tx:advice id="txAdvice" transaction-manager="transactionManager">
        <!--给那些方法配置事务-->
        <!--配置事务的传播特性: new -->
        <tx:attributes>
            <tx:method name="add" propagation="REQUIRED"/>
            <tx:method name="delete" propagation="REQUIRED"/>
            <tx:method name="update" propagation="REQUIRED"/>
            <tx:method name="query" read-only="true"/>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
</tx:advice>

3.配置事务切入

<aop:config>
        <aop:pointcut id="txPointCut" expression="execution(* com.kuang.mapper.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"/>
</aop:config>

标签:xml,事务管理,事务,spring,Spring,dao,aop
来源: https://www.cnblogs.com/lanjieduanxin/p/15969007.html