Spring声明式事务
事务的ACID原则:原子性、一致性、隔离性、持久性。
<!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置增强类 --> <tx:advice id="transAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- transfer方法进行事务 --> <tx:method name="transfer" propagation="REQUIRED" timeout="30" read-only="false" isolation="REPEATABLE_READ"/> <!-- 所有方法进行事务,传播行为默认REQUIRED,隔离级别默认RR、超时-1、是否只读默认false... --> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- aop配置 --> <aop:config> <!-- 定义切入点 --> <aop:pointcut id="pt" expression="execution(* com.service.AccountService.transfer(..))"/> <!-- 将增强类注入到切入点上 --> <aop:advisor advice-ref="transAdvice" pointcut-ref="pt"/> </aop:config>

浙公网安备 33010602011771号