@Test void getUserService() { cglibProxyDemo.getUserService().getUsernameFromSelf("xiaoming"); }
public UserService getUserService(){ Enhancer en = new Enhancer(); en.setSuperclass(userService.getClass()); en.setCallback((MethodInterceptor) (arg0, method, args, arg3) -> { log.info("pre class: {} method: {} return type:{} args:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),args); Object result = method.invoke(userService, args); log.info("post class: {} method: {} return type:{} result:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),result); return result; }); return (UserService) en.create(); }
CglibProxyDemo { public UserService getUserService(){ Enhancer en = new Enhancer(); en.setSuperclass(userService.getClass()); en.setCallback((MethodInterceptor) (arg0, method, args, arg3) -> { log.info("pre class: {} method: {} return type:{} args:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),args); Object result = method.invoke(userService, args); log.info("post class: {} method: {} return type:{} result:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),result); return result; }); return (UserService) en.create(); } }
CglibProxyDemo { public UserService getUserService(){ Enhancer en = new Enhancer(); en.setSuperclass(userService.getClass()); en.setCallback((MethodInterceptor) (arg0, method, args, arg3) -> { log.info("pre class: {} method: {} return type:{} args:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),args); Object result = method.invoke(userService, args); log.info("post class: {} method: {} return type:{} result:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),result); return result; }); return (UserService) en.create(); }  }
CglibProxyDemo { public UserService getUserService(){ Enhancer en = new Enhancer(); en.setSuperclass(userService.getClass()); en.setCallback((MethodInterceptor) (arg0, method, args, arg3) -> { log.info("pre class: {} method: {} return type:{} args:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),args); Object result = method.invoke(userService, args); log.info("post class: {} method: {} return type:{} result:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),result); return result; }); return (UserService) en.create(); }  UserService getUserService(); }
CglibProxyDemo { public UserService getUserService(){ Enhancer en = new Enhancer(); en.setSuperclass(userService.getClass()); en.setCallback((MethodInterceptor) (arg0, method, args, arg3) -> { log.info("pre class: {} method: {} return type:{} args:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),args); Object result = method.invoke(userService, args); log.info("post class: {} method: {} return type:{} result:{}", userService.getClass().getName(),method.getName(),method.getReturnType(),result); return result; }); return (UserService) en.create(); }  UserService getUserService();  }