@Test public void roleServiceTest() { RoleService realService = new RoleServiceImpl(); RoleService proxyService = (RoleService) DynamicProxy.getProxy(realService); boolean hasPrivilege = proxyService.hasPrivilege(new User()); LOGGER.info("roleServiceTest: " + hasPrivilege); }
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);  }