AOP配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans.xsd"
<!-- 配置Service -->
<bean id = "customerService" class="com.itheima.service.impl.CustomerServiceImpl"></bean>
<!-- 基于XML的aop配置步骤    (必须导入aop的jar包)-->
<!-- 1.把通知类交给spring来管理 -->
<bean id="Logger" class="com.itheima.utils.Logger"></bean>
<!-- 2.导入aop名称空间,使用aop:config开始aop配置 -->
<aop:config>
<!-- 3.使用aop:aspect配置切面 id属性用于给切面提供一个唯一标识。
	ref属性用于通知bean的id -->
	<aop:aspect id="LogAdvice" ref="Logger">
	<!-- 4. 配置通知的类型,指定增强的方法何时执行 -->
	<!-- 切入点表达式:-->
	 <aop:pointcut expression="execution(*com..*.*(..))"  id=" pt1"></aop:pointcut>
				<!-- 关键字:execution(表达式) -->
				<!-- 写法:返回值 包名 .包名...类名.方法名(参数列表)
					访问修饰符可以省略
					返回值可以使用通配符 
					包名可以使用通配符,表示任意包,有几个包写几个*
					全匹配方式 *.*..*(..) -->
		<aop:before method="(选定自己的方法)"  pointcut-ref="pt1"/>
		<!-- 后置通知,切入点之后执行 -->
		<aop:after-returning method="after..." pointcut-ref="pt1"></aop:after-returning>
		<aop:after-throwing method="afterThrowing..." pointcut-ref="pt1"></aop:after-throwing>
		<aop:afrer  method="after.." pointcut-ref="pt1"/>
		<!-- 环绕通知 (invoke)方法,并且有明确的pointcut方法调用-->
		<!-- spring 提供接口 ProceedingJoinPoint, 该接口可以作为参数使用
			运行时,spring会提供接口的实现类 -->
		<!-- 接口中方法 proceed(),作用等同于method.invoke方法,明确调用业务层方法 -->
		<aop:around method="around.." pointcut-ref="pt1"/>
	</aop:aspect>
</aop:config>

猜你喜欢

转载自blog.csdn.net/hyf_home/article/details/81706062