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>