获取Spring bean的真实Class对象 [英] Obtain real Class object for Spring bean

查看:908
本文介绍了获取Spring bean的真实Class对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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基于接口的代理实现

Spring's interface-based proxies implement TargetClassAware.

这篇关于获取Spring bean的真实Class对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆