使用@Advice.Origin方法无法使用byte-buddy拦截方法

问题描述 投票:1回答:1

使用下面的例子,当我在我的方法中使用@Advice.Origin Method method作为参数时,我无法拦截方法调用。

public static void premain(String arguments, Instrumentation instrumentation) throws IOException {

  new AgentBuilder.Default()
        .type(ElementMatchers.nameEndsWith("Controller"))
        .transform((builder, type, classLoader, module) -> {
                 return builder.method(ElementMatchers.any()).intercept(MethodDelegation.to(AccessInterceptor.class));
              }
        ).installOn(instrumentation);
}

  @RuntimeType
  public static Object intercept(@Advice.Origin Method method, @SuperCall Callable<?> callable) throws Exception {
     System.out.println("intercept");
     return callable.call();
  }

如果我删除@Advice.Origin Method method,代码就会开始工作

  @RuntimeType
  public static Object intercept(@SuperCall Callable<?> callable) throws Exception {
     System.out.println("intercept");
     return callable.call();
  }
byte-buddy
1个回答
2
投票

@Advice.Origin@Origin之间的区别。建议可以少做委托,但内联其代码。您需要调整导入。

© www.soinside.com 2019 - 2024. All rights reserved.