获取Spring bean的真实Class对象 [英] Obtain real Class object for Spring bean
问题描述
我正在使用Spring注入豆子.我正在使用一些注释来注释bean方法(安全性,TransactionManagement,ExceptionHanling,日志记录).问题是:
I am using Spring to inject beans. And I am using some annotations to annotate bean methods (Security, TransactionManagement, ExceptionHanling, Logging). The problem is:
我想创建JUnit测试来检查是否忘记了一些方法.但是Spring返回的$ ProxyXXX类没有方法上的任何注释..
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(不是CGLib)
P.S. Spring 2.5.6, JDKDynamicProxy (not CGLib)
推荐答案
Spring's interface-based proxies implement TargetClassAware
.
这篇关于获取Spring bean的真实Class对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!