unproxy-a-spring-bean

http://stackoverflow.com/questions/8121551/is-it-possible-to-unproxy-a-spring-bean

http://stackoverflow.com/questions/4409456/how-to-unwrap-the-original-object-from-a-dynamic-proxy

http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/

http://jinnianshilongnian.iteye.com/blog/1613222

@SuppressWarnings({"unchecked"})
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; // expected to be cglib proxy then, which is simply a specialized class
  }
}

你可能感兴趣的:(spring)