Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 391
Dims Avatar asked Apr 01 '15 15:04

Dims


1 Answers

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."

like image 137
James Watkins Avatar answered Sep 26 '22 12:09

James Watkins