【发布时间】:2014-01-30 03:54:22
【问题描述】:
可以在 Spring AOP 中使用 @DeclareMixin 吗?还是他们只支持@DeclareParents?
我想编写一个方面,将 java.beans.PropertyChangeSupport 混合到一个 java bean 中:
public class PropertyChangeSupportWithInterface extends PropertyChangeSupport
implements IObservableBean {
public PropertyChangeSupportWithInterface(Object sourceBean) {
super(sourceBean);
}
}
(IObservableBean 仅包含来自 PropertyChangeSupport 的所有公共方法)
@Aspect
@Named
public class ObservableAspect{
@DeclareMixin("@ObservableBean *")
public static IObservableBean createDelegate(Object object) {
return new PropertyChangeSupportWithInterface(object);
}
}
好像从来没有使用过这个方面,这让我觉得Spring AOP所做的运行时编织不支持@DeclareMixin。
有什么方法可以让它与 Spring AOP 一起工作?
您可以在此处找到一个(未运行的)示例(Maven 多模块项目):
https://github.com/BernhardBln/SpringAOPObservableBean
查看 springaop-observable-bean-aspect 子模块中的(唯一)测试用例。
【问题讨论】:
标签: java aop mixins spring-aop