spring中基于aop的配置步骤
1.把通知bean交给spring管理
2.使用aop:config标签开始aop配置
3,使用aspect配置切面(id标志 ref通知类bean的id)
4.在aspect内部使用对应标签来配置通知类型(AOP:before method)
5.pointcut表示指定切入点表达式
写法:
关键字:execution
表达式:
访问修饰符 包明。。。类名。方法名
public void com.spring_learn,.....
全通配写法:* *..*.*(..)
实际写法:*(包名).*.*(..)
-
通知的其他几种类型
前置,后置,异常,最终。。。 -
切入点
<aop:pointcut id="..." expression="execution(....)"></aop:pointcut>
<aop:aspect id="" ref="...">
<aop:before method="" pointcut-ref=""></aop:before>
</aop:aspect>
环绕
public Object aroundprintLog(ProceedingJoinPoint pjp)
{
Object rvalue = null;
try {
Object[] args = pjp.getArgs();
System.out.println("前置");
rvalue = pjp.proceed(args);//切入点方法
System.out.println("后置");
return rvalue;
}catch (Throwable t)
{
System.out.println("异常");
throw new RuntimeException(t);
}finally {
System.out.println("最终");
}
}