Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save grandadmiralmcb/127e78eca4f19066715ed04a87b8b520 to your computer and use it in GitHub Desktop.
Save grandadmiralmcb/127e78eca4f19066715ed04a87b8b520 to your computer and use it in GitHub Desktop.
Deproxy JDK/CGLib Proxies in Java/Spring
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