Spring AOP 中 IntroductionInterceptor 的疑惑
悬赏:10 发布时间:2008-07-19 提问人:yangdong (初级程序员)
大家好!
小弟近日正在学习Spring 1.2,看的书是《Spring in Action》第一版。在读到 3.4.1 Implementing IntroductionInterceptor 一节时,遇到了下面这个类:
AuditableMixin 的意图是让某个类动态支持 Auditable 接口。
其中,implementsInterface(Class) 这个方法为什么不是
?
作者对于这个函数的解释是:“implementsInterface returns true if the class declaring the invoked method is of type Auditable.”但是,如果 intf 是 Auditable 的子接口类型,而不是 Auditable 自身时,implementsInterface(Class) 会返回 false。这样不合情理吧?
IntroductionInterceptor 的默认实现是 DelegatingIntroductionInterceptor。它继承了 IntroductionInfoSupport。我查了 IntroductionInfoSupport 的源码,它里面这个函数的实现与书中一致:
请教各位,这是我的理解错误还是 Spring 的 bug?
谢谢!
该问题已经关闭: Sorry, guys. My fault.
小弟近日正在学习Spring 1.2,看的书是《Spring in Action》第一版。在读到 3.4.1 Implementing IntroductionInterceptor 一节时,遇到了下面这个类:
package com.springinaction.training.advice;
import java.util.Date;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.IntroductionInterceptor;
public class AuditableMixin implements IntroductionInterceptor, Auditable {
public boolean implementsInterface(Class intf) {
return intf.isAssignableFrom(Auditable.class);
}
public Object invoke(MethodInvocation m) throws Throwable {
if (implementsInterface(m.getMethod().getDeclaringClass())) {
return m.getMethod().invoke(this, m.getArguments());
} else {
return m.proceed();
}
}
private Date lastModifiedDate;
public Date getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(Date lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
AuditableMixin 的意图是让某个类动态支持 Auditable 接口。
其中,implementsInterface(Class) 这个方法为什么不是
public boolean implementsInterface(Class intf) {
return Auditable.class.isAssignableFrom(intf);
}
?
作者对于这个函数的解释是:“implementsInterface returns true if the class declaring the invoked method is of type Auditable.”但是,如果 intf 是 Auditable 的子接口类型,而不是 Auditable 自身时,implementsInterface(Class) 会返回 false。这样不合情理吧?
IntroductionInterceptor 的默认实现是 DelegatingIntroductionInterceptor。它继承了 IntroductionInfoSupport。我查了 IntroductionInfoSupport 的源码,它里面这个函数的实现与书中一致:
public boolean implementsInterface(Class intf) {
for (Iterator it = this.publishedInterfaces.iterator(); it.hasNext();) {
Class pubIntf = (Class) it.next();
if (intf.isInterface() && intf.isAssignableFrom(pubIntf)) {
return true;
}
}
return false;
}
请教各位,这是我的理解错误还是 Spring 的 bug?
谢谢!
该问题已经关闭: Sorry, guys. My fault.
已解决问题数: 959
待解决问题数: 418
已关闭问题数: 1635
待解决问题数: 418
已关闭问题数: 1635




