1

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!

LdSe
  • 334
  • 1
  • 3
  • 17

1 Answers1

1

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!

nickb
  • 59,313
  • 13
  • 108
  • 143
LdSe
  • 334
  • 1
  • 3
  • 17
  • Is there a way to create dynamic pointcuts without spring, just aspectj? What I'm looking for is to create a pointcut with some parameters like class or package name, coming from user input. Thanks – Abhilash Vedwan Sep 24 '15 at 07:49
  • Yes, but you'll need a hook to your objects, which is basically where Spring AOP helps you out. http://www.adevedo.com/content/using-aspectj-log-all-methods-parameters-and-return-values-during-application-runtime – LdSe Jan 08 '16 at 13:27
  • @AbhilashK can we apply dynamic expression for point cut at run time to monitor method execution. Also, If it is possible to create/destroy new aspect bean(instead of modifying point cut expression). Use case is same as you mentioned, when we need to find some error or execution time of method execution we enable these advise in production and than disable once monitor not needed. – Nitul Dec 28 '17 at 14:15
  • @Nitul I did mine using Agent and MXBean. I used Agent to modify all the classes, to generate debug information per method. The modifications uses MXBean which contains information about class/package we need to debug. I then enabled, disabled and configured MXBean using JConsole at runtime. Hope this helps. – Abhilash Vedwan Dec 31 '17 at 03:18
  • @AbhilashK Can you provide me any more details to achieve same? – Nitul Jan 01 '18 at 06:02
  • @Nitul Not sure what details you require, however if its about Agent, MXBean and JConsole, these links might help: Java Agent: https://javabeat.net/introduction-to-java-agents/ MXBean + JConsole: https://www.journaldev.com/1352/what-is-jmx-mbean-jconsole-tutorial/ – Abhilash Vedwan Jan 08 '18 at 07:11
  • @Nitul Simply put, for AspectJ you give pointcut for all possible classes, then if-else for the classes that you want. These if-else can be controlled by creating a bean with ways to add, edit and modify class/package values. – Abhilash Vedwan Jan 08 '18 at 07:20