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();