使用cglib,asm 对接口进行拦截,这里需要调用Invoke方法

        final IUserService userService=new UserService();
        
        Enhancer enhancer=new Enhancer();
        enhancer.setSuperclass(IUserService.class);
        enhancer.setCallback(new MethodInterceptor() {
            
            @Override
            public Object intercept(Object arg0, Method arg1, Object[] arg2,
                    MethodProxy arg3) throws Throwable {
                System.out.println(arg1.getName());
                
                return arg3.invoke(userService, arg2);
            }
        });
        IUserService proxy= (IUserService) enhancer.create();
        System.out.println(proxy.getNameById(3));
View Code

相关文章:

  • 2022-12-23
  • 2022-02-14
  • 2021-08-22
  • 2021-12-25
  • 2022-12-23
  • 2021-07-06
  • 2021-09-30
  • 2021-08-29
猜你喜欢
  • 2021-11-07
  • 2022-01-02
  • 2022-12-23
  • 2021-12-21
  • 2021-05-01
  • 2021-11-18
相关资源
相似解决方案