开发者

How to create an aspect on class, that is not a bean using Spring AOP?

I work on an legacy application, where Spring AOP (namely ProxyFactoryBean) is used.

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 l开发者_运维知识库ike this: execution(* xyz.package.Class.method())

I created a MethodInterceptor and AspectJExpressionPointcut, but I don't know how make those two work together.

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.

Any help appreciated.


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).


Try @Configurable. It is explained in this docs.

The @Configurable annotation marks a class as eligible for Spring-driven configuration

(you'd need <context:load-time-weaver />)

Update You can make a 3rd party component a bean by listing it in applicationContext.xml as <bean class=".." /> (you don't need @Configurable with that)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜