如何在类上创建一个方面,而不是使用Spring AOP的bean? [英] How to create an aspect on class, that is not a bean using Spring AOP?
问题描述
我在使用Spring AOP(即ProxyFactoryBean
)的旧版应用程序上工作.
I work on an legacy application, where Spring AOP (namely ProxyFactoryBean
) is used.
我需要围绕某个类的方法添加一个方面.但是,此类不是不是 bean.
AspecjJ切入点表达式将如下所示:
execution(* xyz.package.Class.method())
I need to add an aspect around a method of a certain class. This class is not a bean however.
The AspecjJ pointcut expression would be like this:
execution(* xyz.package.Class.method())
我创建了MethodInterceptor
和AspectJExpressionPointcut
,但是我不知道如何使两者一起工作.
I created a MethodInterceptor
and AspectJExpressionPointcut
, but I don't know how make those two work together.
编辑:
我没有此类的源代码,它是一个3rd party库.此类的实例不是由我创建的,无论是在源代码中,还是在Spring配置中都没有作为bean.库内部使用它.
EDIT:
I do not have source code for this class, it is a 3rd party library. The instances of this class are not created by me, neither in source code, nor in spring configuration as beans. It is used internally by the library.
任何帮助表示赞赏.
推荐答案
您可以按照其他方法).
You can use load-time weaving with full AspectJ support as described here, it doesn't require access to the source of classes being advised nor control over their instantiation (though it requires <context:load-time-weaver />
and presence of the weaver itself using -javaagent:...
or other methods).
这篇关于如何在类上创建一个方面,而不是使用Spring AOP的bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!