原子性(Atomicity)
一致性(Consistency)
隔离性(Isolation)
持久性(Persistence)
为什么使用声明式事务?
不使用事务,可能存在数据提交不一致的情况
如果不在spring中配置声明式事务,我们就要在代码中手动编写事务
spring中的事务配置
<!--配置声明式事务-->
<bean id="transactionManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
?
<!--结合AOP实现事务的织入-->
<!--配置事务通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManage">
<!--给哪些方法配置事务-->
<!--propagation:事务的传播特性-->
<tx:attributes>
<tx:method name="add" propagation="REQUIRED"/>
<tx:method name="delete" propagation="REQUIRED"/>
<tx:method name="update" propagation="REQUIRED"/>
<tx:method name="select"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
?
<!--配置事务切入-->
<aop:config>
<aop:pointcut id="pointCut" expression="execution(* com.hmx.mapper.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointCut"/>
</aop:config>
原文:https://www.cnblogs.com/LittleSkinny/p/13695185.html