使用以下示例,当我在方法中@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
是有区别的。建议可以比委派做得更少,但会内联其代码。您需要调整导入。