So I'm starting to get into Spring AOP, and something occurred to me. When configuring an aspect, the annotations all use Strings as parameters, rather than Class objects.
I bring this up because this means that an IDE (I use Eclipse, so I'll just refer to it here) won't be able to refactor the aspect properly. So if I have a class MyClass, with a method public void foo(), an example of a Spring AOP annotation would be this:
@Before ("execution(public void package.MyClass.foo())")
Because the param in the annotation is a String, if I refactored the method name to public void foo2(), it would break the binding of this aspect.
I've been scouring various forums and tutorials, but everywhere I look I just see String parameters, which suggests that's the only option here. I guess you could work around this by being a bit more generic in how you declare the binding:
@Before ("exeuction(public void package.MyClass.set*(..))")
This new one will work for any setter method in MyClass, with any number of parameters (or no params). Of course, being vague like this might not work all the time.
Anyway, I'm ranting a little bit here, it's late and I'm kind of tired and my brain is all worn out from hunting for an answer to this. But my final question is this: is there any way to set up Spring AOP annotations so that refactoring will affect them?
Thanks.
Class.getMethod(String name, Class<?>... parameterTypes)
, for example, requires a String, but there's no way around that. That's probably what Spring uses. I agree that it would have to involve an Eclipse configuration. – Lucas Ross@Before
is an AspectJ annotation and NOT a spring annotation. This is rather about the tooling support for annotation driven aspects if you write realaspect
s (public aspect MyAspect
instead of@Aspect public class MyAspect
you get this support at least partially). The greater question is the IDE support instead of framework support. – M. Deinum