Created
October 23, 2017 14:43
-
-
Save grandadmiralmcb/127e78eca4f19066715ed04a87b8b520 to your computer and use it in GitHub Desktop.
Deproxy JDK/CGLib Proxies in Java/Spring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProxyUtils { | |
@SuppressWarnings({ "unchecked" }) | |
public <T> T getTargetObject(Object proxy) throws Exception { | |
while ((AopUtils.isJdkDynamicProxy(proxy))) { | |
return (T) getTargetObject(((Advised) proxy).getTargetSource().getTarget()); | |
} | |
return (T) proxy; // expected to be cglib proxy then, which is simply a | |
// specialized class | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment