Just thinking about it now I think I'm asking the wrong question, I think I need to find out how to be able to access the Annotation values in the Advice without using CGLIB. Is this possible?
The code looks like this
Code:
public @interface CustomAnnotation {
String customValue = null;
public String getCustomValue() { return customValue; }
}
Code:
public interface Foo {
public void doFoo();
}
Code:
public class FooImpl implements Foo {
@CustomAnnotation(customValue="")
public void doFoo() {
....
}
}
Code:
@Aspect
public class FooAdvice {
@Before(value = "@annotation(Foo)")
public void checkCustomValue(JoinPoint jp) throws Throwable {
MethodSignature methodSignature = (MethodSignature)jp.getSignature();
Method method = methodSignature.getMethod();
CustomAnnotation annotation = method.getAnnotation(CustomAnnotation.class);
if( annotation.getCustomValue().equals("......."){
....;
}
}
}
With the above code the annotaion.getCustomValue() throws a NullPointerException because the annotation is not present. This is overcome by either annotating BOTH the implementation and the interface (*screws up face*) or using CGLIB to proxy classes, which as I already mentioned will not play well with our other code.
Hmmmmmm well after typing all of that out I was secretly hoping that I would work out my problem by the time I finished typing.... well it turns out I haven't, haha, so any suggestions?