I\'d like to access the classname of the underlying class which is an instance of java.lang.reflect.Proxy.
Is this possible?
I found a good solution on this site (now archived):
@SuppressWarnings({"unchecked"})
protected T getTargetObject(Object proxy, Class targetClass) throws Exception {
if (AopUtils.isJdkDynamicProxy(proxy)) {
return (T) ((Advised)proxy).getTargetSource().getTarget();
} else {
return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
}
}
Usage
@Override
protected void onSetUp() throws Exception {
getTargetObject(fooBean, FooBeanImpl.class).setBarRepository(new MyStubBarRepository());
}