How to create an aspect in a class rather than a bean using Spring AOP?

I am working on an outdated application that uses Spring AOP (namely ProxyFactoryBean ).

I need to add an aspect around the method of a particular class. This class is not a bean. The expression pointcut AspecjJ will be as follows: execution(* xyz.package.Class.method())

I created MethodInterceptor and AspectJExpressionPointcut , but I don’t know how to make these two work together.

EDIT :
I do not have source code for this class, this is a third-party library. Instances of this class are not created by me, neither in the source code, nor in the Spring configuration, like beans. It is used inside the library.

Any help was appreciated.

+4
source share
2 answers

You can use loading weaving with full AspectJ support, as described here , it does not require access to the source of the classes being (although this requires <context:load-time-weaver /> and the weaver itself, using -javaagent:... or other methods ).

+3
source

Try @Configurable . This is explained in these documents .

@Configurable annotation marks a class as appropriate for Spring-Driven configuration

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

Update You can make a third-party bean by specifying it in applicationContext.xml as <bean class=".." /> (you don't need @Configurable with this)

+3
source

Source: https://habr.com/ru/post/1304456/


All Articles