无法使用 @Advice.Origin 方法截获带有字节伙伴的方法



使用以下示例,当我在方法中@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();
}

>@Advice.Origin@Origin是有区别的。建议可以比委派做得更少,但会内联其代码。您需要调整导入。

最新更新