1.创建增强类的对象,和被增强类的对象
2.确立增强类和目标的关系
2.1 关系的名字,增强目标的位置以及类型,参数格式
2.2 指定增强类
2.2.1 确认增强类型(哪方面) 比如前置,后置,
2.2.3 关联关系的id,确立关系
创建增强类的对象和目标的对象
<!--创建service对象-->
<bean id="us1" class="com.fdk.service.impl.UserServiceImpl"></bean>
<!--1.创建增强对象-->
<bean id="aop1" class="com.fdk.aop.MyAop"></bean>
2:建立增强类和目标的关系
<!--2.定义增强类和目标方法的关系-->
<aop:config>
<!-- pointcur 切入点,id自定义,expression(表达)写的是切入的格式
execution(执行)方法的格式-->
<aop:pointcut id="pc1" expression="execution(public void selectAll(..))"/>
<!--ref="增强类的对象"-->
<!--aspect(方面)-->
<aop:aspect ref="aop1">
<!--定义增强的类型:before表示前置增强-->
<aop:before method="begins" pointcut-ref="pc1"/>
<!--环绕增强-->
<aop:around method="arounds" pointcut-ref="pc1" ></aop:around>
<!--后置增强-->
<aop:after-returning method="afters" pointcut-ref="pc1"/>
<!--异常增强-->
<aop:after-throwing method="exceptions" pointcut-ref="pc1"/>
<!--最终增强-->
<aop:after method="fillays" pointcut-ref="pc1"/>
</aop:aspect>
</aop:config>
环绕增强时,调用目标方法
public Object arounds(ProceedingJoinPoint jp) throws Throwable {
System.out.println("方法环绕");
//proceed 继续
Object obj=jp.proceed();
System.out.println("环绕结束"+obj);
return obj;
}