Question

Here's the thing, I've been working on a Monitoring solution with AOP, that can be extended to any kind of component. I'll try to break my concern in areas.

The idea:
Have a mechanism that allows dynamic pointcut expressions definition based on types, which are Spring beans.

What I did:
Created a component which implements ApplicationContextAware, that inspects the Spring Context and makes a list of all the bean types and names that should be considered for the Pointcut.

The problem:
The problem with this is that, at this point, I can't redefine or use any Pointcut, since the Spring AOP process has already created the proxyed objects.

What I tried:
• Implemented my own Pointcut, Advisor and Advice, which compares against my list of beans, however, it's being ignored.
• Implemented a PointcutFactoryBean, which would be the one that provides the Pointcut to the already declared Advisor.
• Tried modifying an already declared Pointcut (Adding the new expression based on the beanIds) and associating it to a BeanNameAutoProxyCreator, with an Interceptor associated to this Pointcut. So that it'd have, for example:
bean(bean1) || bean(otherBean), and so on.

With all these tries, I stumbled upon the same problem, everything is already defined and unalterable from the context.

The question:
Is this even possible to do with Spring AOP? We don't want to involve any AspectJ matter to this, such as weaving and so on... To summarize, I'm looking for a way to create a pointcut expression and assign it to a pointcut on the application startup, taking in consideration all the beans.

Hope I was clear, if not, please, let me know and I'll do my best to provide further details or code.

Thanks a lot in advance!

Was it helpful?

Solution

Been able to do this by creating my own implementation of each class related to AOP:

  • Pointcut.
  • MethodMatcher.
  • ParentsAdvisor.
  • ClassFilter.

And instanciating them directly using Spring, adding an empty aop:config element in the Spring context was enough to have this working flawlessly.

If anyone needs more information, just let me know.

Thanks!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top