**将事务控制类(TransactionManager)看成是一个通知类 **
1.导入spring 开启AOP的约束(在bean.xml)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--配置Spring容器创建时候要扫描的包-->
<context:component-scan base-package="com.itheima"></context:component-scan>
<!--配置Spring开启注解aop的支持-->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
.......
<!-- 配置事务管理器(配置通知类)-->
<bean id="txManager" class="com.itheima.utils.TransactionManager">
<!-- 注入ConnectionUtils -->
<property name="connectionUtils" ref="connectionUtils"></property>
</bean>
<aop:config>
<aop:aspect id="txAdvice" ref="txManager">
<!--前置通知:开启事务-->
<aop:after method="beginTransaction" pointcut="execution(* com.itheima.utils.*.*(..))"></aop:after>
<!--后置通知:提交事务-->
<aop:after-returning method="commit" pointcut="execution(* com.itheima.utils.*.*(..))"></aop:after-returning>
<!--异常通知:回滚事务-->
<aop:after-throwing method="rollback" pointcut="execution(* com.itheima.utils.*.*(..))"></aop:after-throwing>
<!--最终通知:释放资源-->
<aop:after method="release" pointcut="execution(* com.itheima.utils.*.*(..))"></aop:after>
</aop:aspect>
</aop:config>
</beans>