Spring 声明式事务配置
Spring 声明式事务
1)spring的事务管理是通过Aop的方式来实现;
2)声明式事务是spring对事务管理的最常用的方式,因为这种方式对代码的影响最小,因此也就符合非侵入式的轻量级的容器的概念;
3)我们需要理解事务的概念,这里不再给出详细说明。
spring 配置文件
<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSources"/>
</bean>
<!--配置事务增强(如何管理事务,只读、读写...也就是配置事务的隔离特效)-->
<!-- <tx:advice/>有一个transaction-manager属性,我们可以用它来指定我们的事物由谁来管理。 -->
<tx:advice id="interceptor" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*save*" read-only="false"/>
<tx:method name="*get*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!--配置切面-aop配置,拦截哪些方法(切入点表达式,拦截上面的事务增强)-->
<aop:config >
<aop:pointcut id="pointcut" expression="execution(* com.wzx.studyspringboot.SpringTxManage.*.*(..))"></aop:pointcut>
<aop:advisor advice-ref="interceptor" pointcut-ref="pointcut"></aop:advisor>
</aop:config>
<!--开启注解扫描-->
<context:component-scan base-package="com.wzx.studyspringboot.SpringTxManage"/>
<!--开启注解事务-->
<tx:annotation-driven></tx:annotation-driven>
本文作者:志旋
本文链接:https://www.cnblogs.com/wuzhixuan/p/12890677.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步