Obtain real Class object for Spring bean

岁酱吖の 提交于 2019-11-28 21:15:51
axtavt

Spring's interface-based proxies implement TargetClassAware.

You can cast the proxied object to get the object and class it acts as a proxy for (see TargetSource):

Advised advised = (Advised) proxy;
Class<?> cls = advised.getTargetSource().getTargetClass();

Generally you should follow the Spring principles and keep obtaining the correct class as unobtrusive as possible. Meaning that as little classes as possible should depend on the Spring Framework APIs (maybe add a ClassLocator and a SpringProxyClassLocator implementation).

Korobko Alex

Or you can just call: AopUtils.getTargetClass(java.lang.Object) It is a static method call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!