一、AOP的简单实用Demo
beans.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd ">
<!-- bean definition & AOP specific configuration -->
<bean id="studentService" class="com.kjgym.service.impl.StudentServiceImpl"></bean>
<bean id="studentServiceAspect" class="com.kjgym.advice.StudentServiceAspect"></bean>
<!-- AOP简单配置 -->
<aop:config>
<aop:aspect id="studentServiceAspect2" ref="studentServiceAspect">
<!--
execution()方法表达式
* com.kjgym.service.*.*(..)
第一个 * 代表返回值
*代表任意, *.*代表service包下任意类
小括号里代表方法,两个点代表任意参数
-->
<aop:pointcut expression="execution(* com.kjgym.service.*.*(..))" id="businessService"/>
<!-- 切入方式:前置 后置 环绕 返回 异常 -->
<!-- method的值对应 id="studentServiceAspect2" 里面的方法 -->
<aop:before method="doBefore" pointcut-ref="businessService"/>
<aop:after method="doAfter" pointcut-ref="businessService"/>
<aop:around method="doAround" pointcut-ref="businessService"/>
<aop:after-returning method="doAfterReturning" pointcut-ref="businessService"/>
<aop:after-throwing method="doAfterThrowing" pointcut-ref="businessService" throwing="ex"/>
</aop:aspect>
</aop:config>
</beans>