How to know original class name if wrapped into proxy by Spring?

让人想犯罪 __ 提交于 2019-12-22 06:49:23

问题


I am trying to obtain some classes name by getClass().getSimpleName() under Spring and it returns something like

MyClass$$EnhancerBySpringCGLIB$$SOMEHEX

This is probably because Spring wraps the class into proxy.

Is there any portable way to obtain original class name?


回答1:


Spring provides a utility for this.

http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/ClassUtils.html#getUserClass-java.lang.Class-

public static Class<?> getUserClass(Class<?> clazz)

"Return the user-defined class for the given class: usually simply the given class, but the original class in case of a CGLIB-generated subclass."



来源:https://stackoverflow.com/questions/29395202/how-to-know-original-class-name-if-wrapped-into-proxy-by-spring

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