不能用byte-buddy with @Advice.Origin Method拦截方法
Cannot intercept the method with byte-buddy with @Advice.Origin Method
使用以下示例,当我在方法中将 @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
有区别。建议可以做的比委托少,但内联它的代码。您需要调整导入。
使用以下示例,当我在方法中将 @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
有区别。建议可以做的比委托少,但内联它的代码。您需要调整导入。