@Test public void randomUserServiceTest() { UserService realService = new UserServiceImpl(new RandomOutServiceImpl(50)); UserService proxyService = (UserService) DynamicProxy.getProxy(realService); User user = proxyService.queryUser(new QueryUserCondition()); LOGGER.info("randomUserServiceTest: " + user); }
public static Object getProxy(Object realSubject) { InvocationHandler handler = new DynamicProxy(realSubject); return Proxy.newProxyInstance(handler.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), handler); }
DynamicProxy implements InvocationHandler { public static Object getProxy(Object realSubject) { InvocationHandler handler = new DynamicProxy(realSubject); return Proxy.newProxyInstance(handler.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), handler); } }
DynamicProxy implements InvocationHandler { public static Object getProxy(Object realSubject) { InvocationHandler handler = new DynamicProxy(realSubject); return Proxy.newProxyInstance(handler.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), handler); } DynamicProxy(Object subject); }
DynamicProxy implements InvocationHandler { public static Object getProxy(Object realSubject) { InvocationHandler handler = new DynamicProxy(realSubject); return Proxy.newProxyInstance(handler.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), handler); } DynamicProxy(Object subject); @Override Object invoke(Object proxy, Method method, Object[] args); static Object getProxy(Object realSubject); }
DynamicProxy implements InvocationHandler { public static Object getProxy(Object realSubject) { InvocationHandler handler = new DynamicProxy(realSubject); return Proxy.newProxyInstance(handler.getClass().getClassLoader(), realSubject.getClass().getInterfaces(), handler); } DynamicProxy(Object subject); @Override Object invoke(Object proxy, Method method, Object[] args); static Object getProxy(Object realSubject);  }