<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 https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="accountService" class="cn.gpxxg.service.Impl.AccountServiceImpl"></bean>
<!--配置loger通知类-->
<bean id="loger" class="cn.gpxxg.utils.Loger"></bean>
<!--配置aop-->
<aop:config>
<!--
aop:pointcut用于配置公共的切面表达式
id:用于执行唯一的id名称
expression:切面表达式的内容
注意:
1、此标签写在aop:aspect标签内部时,只有当前切面使用
2、写在aop:aspect上方时,所有切面都可使用
3、不可写在aop:aspect下方,因为当前xml的约束不允许
-->
<aop:pointcut id="p1" expression="execution(* cn.gpxxg.service.Impl.*.*(..))"></aop:pointcut>
<!--配置切面使用aop:aspect标签-->
<aop:aspect id="logAdvice" ref="loger">
<!--
1、配置通知的类型 before 前置通知
2、建立通知方法和切入点方法的关联
2.1 通知方法 method
2.2 切入点 pointcut
书写格式:execution (修饰符 返回值类型 全限定类名.方法名())
标准写法:public void cn.gpxxg.service.Impl.AccountServiceImpl.save()
通配符简化书写:
修饰符可以省略:void cn.gpxxg.service.Impl.AccountServiceImpl.save()
返回值类型可以使用*来代表所有返回值类型:* cn.gpxxg.service.Impl.AccountServiceImpl.save()
包名可以使用通配符,但有几级包,就要写几个:* *.*.*.*.AccountServiceImpl.save()
包名可以使用..表示当前包及其子包:* *..AccountServiceImpl.save()
类名和方法名可以使用*表示所有:* *..*.*()
参数列表:可以直接写基本数据类型,但引用数据类型需要写包名.类名的方式,如:java.lang.String
全通配符的写法,* *..*.*(..)有无参数均可,可以是任意数据类型
但日常不这样写,实际开发中切入点只会切换到service业务层的所有方法下,即:* cn.gpxxg.service.Impl.*.*(..)
-->
<!--前置通知,在切入点方法之前先执行-->
<aop:before method="beforePrintLog" pointcut-ref="p1"></aop:before>
<!--后置通知,在切入点方法之后执行,它和异常通知只会执行一个-->
<aop:after-returning method="afterReturningPrintLog" pointcut-ref="p1"></aop:after-returning>
<!--异常通知,在遇到异常时执行,它和后置通知只会执行一个-->
<aop:after-throwing method="afterthrowingPrintLog" pointcut-ref="p1"></aop:after-throwing>
<!--最终通知,不管有没有异常都会执行-->
<aop:after method="afterPrintLog" pointcut-ref="p1"></aop:after>
</aop:aspect>
</aop:config>
</beans>