當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
spring aop实现过程之三Spring AOP中Aspect编织的实现
生活随笔
收集整理的這篇文章主要介紹了
spring aop实现过程之三Spring AOP中Aspect编织的实现
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.上節(jié)我們談到攔截器起作用時,實現(xiàn)代碼(ReflectiveMethodInvocation.java)如下:
public Object proceed() throws Throwable {// We start with an index of -1 and increment early.if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) {return invokeJoinpoint();}Object interceptorOrInterceptionAdvice =this.interceptorsAndDynamicMethodMatchers.get(++this.currentInterceptorIndex);if (interceptorOrInterceptionAdvice instanceof InterceptorAndDynamicMethodMatcher) {// Evaluate dynamic method matcher here: static part will already have// been evaluated and found to match.InterceptorAndDynamicMethodMatcher dm =(InterceptorAndDynamicMethodMatcher) interceptorOrInterceptionAdvice;if (dm.methodMatcher.matches(this.method, this.targetClass, this.arguments)) {return dm.interceptor.invoke(this);}else {// Dynamic matching failed.// Skip this interceptor and invoke the next in the chain.return proceed();}}else {// It's an interceptor, so we just invoke it: The pointcut will have// been evaluated statically before this object was constructed. return ((MethodInterceptor) interceptorOrInterceptionAdvice).invoke(this);}}2.前置Advice MethodBeforeAdviceInterceptor.java
public Object invoke(MethodInvocation mi) throws Throwable {this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis() );return mi.proceed();}3.后置Advice AfterReturningAdviceInterceptor.java
public Object invoke(MethodInvocation mi) throws Throwable {Object retVal = mi.proceed();this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());return retVal;}?
轉(zhuǎn)載于:https://www.cnblogs.com/davidwang456/archive/2013/03/19/2969479.html
總結(jié)
以上是生活随笔為你收集整理的spring aop实现过程之三Spring AOP中Aspect编织的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring aop实现过程之二Spri
- 下一篇: 数据库常用面试题(SQL Server)