If you need to get the proxied object, use this code:
protected ‹T› T getTargetObject(Object proxy, Class‹T› targetClass) throws Exception {
if (AopUtils.isJdkDynamicProxy(proxy)) {
return (T) ((Advised)proxy).getTargetSource().getTarget();
} else {
return (T) proxy;
}
}
Code is taken from this blogpost http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/


No comments:
Post a Comment