| 用TransactionTemplate或者直接使用底层的PlatformTransactionManager将事务代码写在业务代码中。 采用@Transactional注解或者基于配置文件方式,在方法前后进行拦截。非SpringBoot工程,需要在配置文件中加入配置: 
 <tx:annotation-driven/> 
 SpringBoot工程可以用@EnableTransactionManagement注解代替上面的配置内容。 <aop:config>       <aop:pointcut expression="execution(public * com.creditease.permission.service.impl.*Impl.*(..))" id="pointcut"/>       <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>   </aop:config>   <tx:advice id="txAdvice" transaction-manager="transactionManager">       <tx:attributes>           <tx:method name="query*" propagation="REQUIRED" read-only="true"/>           <tx:method name="find*" propagation="REQUIRED" read-only="true"/>           <tx:method name="save*" propagation="REQUIRED"/>           <tx:method name="delete*" propagation="REQUIRED"/>           <tx:method name="add*" propagation="REQUIRED"/>           <tx:method name="modify*" propagation="REQUIRED"/>       </tx:attributes>   </tx:advice> 
 (编辑:南平站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |