使用下面的例子,当我在我的方法中使用@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
之间的区别。建议可以少做委托,但内联其代码。您需要调整导入。