1
votes

At the moment I'm working on an application that should be integrated in any Spring based web application to enable the user to define dynamic pointcuts by changing the value of the @Pointcut annotation at runtime. My primary goal is to switch the method a certain aspect is woven around while the appliaction is still running.

So far, I got it working to start a Spring application context defining an aspect class from a main method and change the annotation value via Reflection. However, it seemed to me that this change didn't affect the proxy object created by Spring. The aspect was still woven and called according to the original @Pointcut value before my changes were applied. The idea to try this came up to me because according to "Spring in Action" and the Spring documentation these proxy objects are created at runtime. So I concluded that there must be a way to provide runtime changes.

Does anyone know if there's another way apart from my approach to get that working using Spring AOP? I'm looking forward to your ideas and opinions!

EDIT: It's important for my solution to leave existing code untouched if that's possible. So adding or replacing methods in beans is not an option for me.

1
Did you happen to find a solution for this?Anand Varkey Philips

1 Answers

3
votes

There are 2 ways to do what you want.

Spring Method Injection. (Add new method) and Method Replacer (Replace a method in a bean)

Ideal if it is for one off bean and not for a set of beans.

Around Aspect.

Ideal if you need to use a point-cut and apply to a set of unknown number of beans. Important: only an AROUND aspect can by-pass the actual target call. And that is done by simply skipping (or invoking conditionally) the proceedingJointPoint.proceed(...) method.

Choose the best that fits your needs.