- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
是否可以将 @DeclareMixin 与 Spring AOP 一起使用?或者他们只支持@DeclareParents?
我想编写一个将 java.beans.PropertyChangeSupport 混合到 java bean 中的方面:
public class PropertyChangeSupportWithInterface extends PropertyChangeSupport
implements IObservableBean {
public PropertyChangeSupportWithInterface(Object sourceBean) {
super(sourceBean);
}
}
(IObservableBean 仅包含 PropertyChangeSupport 中的所有公共(public)方法)
@Aspect
@Named
public class ObservableAspect{
@DeclareMixin("@ObservableBean *")
public static IObservableBean createDelegate(Object object) {
return new PropertyChangeSupportWithInterface(object);
}
}
似乎从来没有使用过这个方面,这让我认为@DeclareMixin 不被Spring AOP 完成的运行时织入支持。
有什么方法可以让它与 Spring AOP 一起工作吗?
您可以在此处找到一个(未)运行的示例(Maven 多模块项目):
https://github.com/BernhardBln/SpringAOPObservableBean
请参阅 springaop-observable-bean-aspect 子模块中的(唯一)测试用例。
最佳答案
不,Spring AOP 不支持开箱即用。我看到两个选项:
DeclareMixinIntroductionInterceptor
。 我认为 PropertyChange
接口(interface)更适合 Aspectj,因为通常您会为原型(prototype) bean 创建很多代理,并且它们可以在框架之外轻松创建,例如通过 ORM。
编辑
但是我也对这个功能很感兴趣并且我已经做了一些工作来使用它:
DeclareMixin
注释。要使用它,您只需要声明一个类型为 DeclareMixinAutoProxyCreatorConfigurer 的 bean。用于使用上面的 AdvisorFactory
配置 AnnotationAwareAspectJAutoProxyCreator
。
我只是在测试,但似乎工作正常。
关于java - @DeclareMixin 使用 Spring AOP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21056795/
我第一次尝试使用@DeclareMixin,要么我做错了什么,要么某个地方有错误。 我已将示例代码发布到 github:https://github.com/benze/AspectJError.gi
我正在使用 aspectjrt-1.6.11 提供的 @DeclareMixin。 情况是: @Aspect public class anAspect { @Declar
是否可以将 @DeclareMixin 与 Spring AOP 一起使用?或者他们只支持@DeclareParents? 我想编写一个将 java.beans.PropertyChangeSuppo
我试图为 java.lang#Object 声明的方法提供默认实现。这是一个MCVE对于我遇到的问题。在接口(interface) IAspect 中我声明了一个 equals 方法。在这个类的实现中
我正在试验 AspectJ 的 @DeclareMixin 功能,但我不断收到此错误: /media/thomas/data-disk/sandbox/java/aspectj-tests/src/m
我是一名优秀的程序员,十分优秀!