SpringAOP配置:
必须代理类
每个Service必须注册一个代理类
AOP-XML配置
SpringAOP注解:
每个Service类的每个方法都有添加注解
AOP-注解配置
AspectJ注解配置:一般推荐使用这种
在基于之前的jar包下新添
apsetj-weaver.jar spring-aspectj.jar
xml配置
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--配置事务事务通知,引入tx约束 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<!--配置事务属性 -->
<tx:attributes>
<tx:method name="open*" isolation="DEFAULT" propagation="REQUIRED"/>
<tx:method name="buy*" isolation="DEFAULT" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<aop:config>
<!--配置切入点,配置切入点表达式 -->
<aop:pointcut expression="execution(* *..service.*.*(..))" id="txpointcut"/>
<!-- 配置事务 -->
<aop:advisor advice-ref="txadvice" pointcut-ref="txpointcut"/>
</aop:config>
tx:method 当中表示通配符,name可以写方法全名或者利用表达都可以
来源:https://blog.csdn.net/qq_32749073/article/details/99755749