<?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:context="http://www.springframework.org/schema/context"
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/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="accountDao" class="com.li.dao.AccountDao"></bean>
<!-- 使用spring的xml的aop配置步骤 -->
<!-- 准备: 导入jar 使用aop约束 步骤: 通知bean也交给spring来管理 通知aop名称空间下的aop;config标签开始aop配置
使用aop:aspect标签,开始配置切面 id属性:用于提供给切面标识 ref属性:用于引用通知bean和id 使用aop:before 配置前置标签通知
method属性。查看那个方法是前置通知 表达式的写法: 全访问路径 execution(public void com.li.dao.AccountDao.findAllAcount())
可以省略修饰符 execution(void com.li.dao.AccountDao.findAllAcount()) 可以使用*代替任意返回值
execution(* com.li.dao.AccountDao.findAllAcount()) 可以使用* 代替包名,有几级就写几个* execution(*
*.*.*.AccountDao.findAllAcount()) 可以使用..代替包下的子类和下下级 execution(* com..AccountDao.findAllAcount())
类名可以使用*代替 方法名可以使用*代替 参数列表 基本类型写 int 引用数据用 java.lang.String 参数列表可以使用*代替,表示任意参数,必须有参数;
参数使用..,表示有无参数均可 实际使用: 一般都是根据需求来,比较常用的是对业务层进行增强。 -->
<bean id="logger" class="com.li.log.LogUtils"></bean>
<aop:config>
<!-- 写入要监控的切面 ,只能在当前界面使用,写在aop:aspect标签外面-->
<aop:pointcut expression="execution(* com..*.*(..))" id="pt"/>
<aop:aspect id="logAdvice" ref="logger">
<!-- 前置通知 -->
<aop:before method="beforePrint"
pointcut="execution(* com..*.*(..))" />
<!-- 后置通知 -->
<aop:after-returning method="afterPrint"
pointcut="execution(* com..*.*(..))" />
<!-- 异常通知 -->
<aop:after-throwing method="throwPrint"
pointcut="execution(* com..*.*(..))" />
<!-- 结束通知 -->
<aop:after method="after"
pointcut-ref="pt" />
<!-- 环绕通知 ,相当于全部代理切入点方法。下面的方法会被拦截,会进入这里
<aop:around method="around" pointcut="execution(* com..*.*(..))"/>
-->
</aop:aspect>
</aop:config>
</beans>