Spring学习心得(二)
1. advice有四种:Before advice ,After advice ,Around advice ,Throws advice
2. 这四种advice分别需要继承的接口为
Advice type
|
Interface
|
Throws advice
|
org.aopalliance.intercept.MethodInterceptor
|
Before advice
|
org.springframework.aop.BeforeAdvice
|
After advice
|
org.springframework.aop.AfterReturningAdvice
|
Throws advice
|
org.springframework.aop.ThrowsAdvice
|
3.Around advice和Before advice的区别是Before advice是只要没有异常,目标方法一定会被调用,然而Around advice,只有当调用MethodInvocation.proceed()后目标方法才能被调用。而且Around advice还可以返回想返回的值:如Object obj=invocation.proceed();