@Test public void testCglibGetProxy() { ProxyFactory proxyFactory = new ProxyFactory(); Audi audi = new Audi(); TargetSource targetSource = new SingletonTargetSource(audi); proxyFactory.setTargetSource(targetSource); Advisor[] advisors = new Advisor[1]; advisors[0] = advisorAdapterRegistry.wrap(new TestMethodInterceptor()); proxyFactory.addAdvisors(advisors); Audi proxy = (Audi) proxyFactory.getProxy(); Audi obj = SpringProxyUtils.getRealTarget(proxy); assertEquals(audi, obj); }
public static <T> T getRealTarget(Object proxy) { Assert.notNull(proxy, "proxy not null"); while (AopUtils.isAopProxy(proxy)) { ProxyFactory proxyFactory = getProxyFactory(proxy); if (proxyFactory == null) { return null; } ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(proxyFactory); TargetSource targetSource = (TargetSource) accessor.getPropertyValue("targetSource"); if (targetSource == null) { return null; } try { proxy = targetSource.getTarget(); } catch (Exception e) { e.printStackTrace(); } } return (T) proxy; }
SpringProxyUtils { public static <T> T getRealTarget(Object proxy) { Assert.notNull(proxy, "proxy not null"); while (AopUtils.isAopProxy(proxy)) { ProxyFactory proxyFactory = getProxyFactory(proxy); if (proxyFactory == null) { return null; } ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(proxyFactory); TargetSource targetSource = (TargetSource) accessor.getPropertyValue("targetSource"); if (targetSource == null) { return null; } try { proxy = targetSource.getTarget(); } catch (Exception e) { e.printStackTrace(); } } return (T) proxy; } }
SpringProxyUtils { public static <T> T getRealTarget(Object proxy) { Assert.notNull(proxy, "proxy not null"); while (AopUtils.isAopProxy(proxy)) { ProxyFactory proxyFactory = getProxyFactory(proxy); if (proxyFactory == null) { return null; } ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(proxyFactory); TargetSource targetSource = (TargetSource) accessor.getPropertyValue("targetSource"); if (targetSource == null) { return null; } try { proxy = targetSource.getTarget(); } catch (Exception e) { e.printStackTrace(); } } return (T) proxy; }  }
SpringProxyUtils { public static <T> T getRealTarget(Object proxy) { Assert.notNull(proxy, "proxy not null"); while (AopUtils.isAopProxy(proxy)) { ProxyFactory proxyFactory = getProxyFactory(proxy); if (proxyFactory == null) { return null; } ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(proxyFactory); TargetSource targetSource = (TargetSource) accessor.getPropertyValue("targetSource"); if (targetSource == null) { return null; } try { proxy = targetSource.getTarget(); } catch (Exception e) { e.printStackTrace(); } } return (T) proxy; }  static T getRealTarget(Object proxy); static boolean isMultipleProxy(Object proxy); static ProxyFactory findJdkDynamicProxyFactory(Object proxy); static ProxyFactory findCglibProxyFactory(Object proxy); static boolean isTransactional(Object proxy); static void removeTransactional(Object proxy); static boolean isAsync(Object proxy); static void removeAsync(Object proxy); }
SpringProxyUtils { public static <T> T getRealTarget(Object proxy) { Assert.notNull(proxy, "proxy not null"); while (AopUtils.isAopProxy(proxy)) { ProxyFactory proxyFactory = getProxyFactory(proxy); if (proxyFactory == null) { return null; } ConfigurablePropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(proxyFactory); TargetSource targetSource = (TargetSource) accessor.getPropertyValue("targetSource"); if (targetSource == null) { return null; } try { proxy = targetSource.getTarget(); } catch (Exception e) { e.printStackTrace(); } } return (T) proxy; }  static T getRealTarget(Object proxy); static boolean isMultipleProxy(Object proxy); static ProxyFactory findJdkDynamicProxyFactory(Object proxy); static ProxyFactory findCglibProxyFactory(Object proxy); static boolean isTransactional(Object proxy); static void removeTransactional(Object proxy); static boolean isAsync(Object proxy); static void removeAsync(Object proxy);  }