views:

73

answers:

2

Hello,

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

A: 

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)

Bozho
I do not have source for this class, it's 3rd party library.
Ula Krukar
then why not add it to applicationContext.xml ? (see my update)
Bozho
Ok, but how can I add @Configurable on bean created like that?
Ula Krukar
you don't need @Configurable with this option - the class is already a bean
Bozho
I updated the question with more details. Sadly, I think this approach is not going to help me,
Ula Krukar
+2  A: 

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

axtavt