Obtain real Class object for Spring bean

Pavel Vyazankin picture Pavel Vyazankin · Feb 18, 2010 · Viewed 17.6k times · Source

I am using Spring to inject beans. And I am using some annotations to annotate bean methods (Security, TransactionManagement, ExceptionHanling, Logging). The problem is:

I want to create JUnit test to check if I forgot annotate some methods. But Spring returns $ProxyXXX class without any annotations on methods..

Method[] methods = logic.getClass().getMethods();

  for (Method method : methods) {
     Annotation[] annotations = method.getAnnotations();   // empty array!

How can I get annotations for method or obtain a real class object?

P.S. Spring 2.5.6, JDKDynamicProxy (not CGLib)

Answer

axtavt picture axtavt · Feb 18, 2010

Spring's interface-based proxies implement TargetClassAware.