CDI interceptor does not see the annotations of the target class
Issue
I have an interceptor installed on a POJO with the @AuditMethods annotation:
public class ChildAction {
private static Logger log = Logger.getLogger(ChildAction.class);
@AuditMethods
public void doIt() {
Thread.dumpStack();
log.info("Done.");
}
@CheckPrecondition
public void checkPrecondition() {
}
}
And the interceptor is trying to read the annotations on each method:
@AuditMethods @Interceptor
public class AuditMethodsInterceptor {
private static Logger log = Logger.getLogger(AuditMethodsInterceptor.class);
@AroundInvoke
public Object printMethods(InvocationContext ctx) throws Exception {
Class<?> clazz = ctx.getTarget().getClass();
for(Method method : clazz.getDeclaredMethods()) {
for(Annotation a : method.getAnnotations()) {
log.info(" " + a.getClass().getName() + ", " + a.annotationType());
}
}
return ctx.proceed();
}
}
When doIt() is invoked on an injected proxy of ChildAction, the interceptor gets the ChildAction proxy as the target. This class doesn’t have the annotations added to it, though. How can I get them?
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 6.x
- Contexts and Dependency Injection in Java EE (CDI)
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
