【发布时间】:2017-07-20 15:38:18
【问题描述】:
我正在尝试将 byte Buddy 用于更大的应用程序。我现在的意思是使用@Advice 在方法进入/退出中记录一些内容。我的代理正确附加到应用程序并已构建。在日志中我还可以看到指向类的转换也完成了。问题是当我在需要的 RestEndpoint 上发送请求并调用方法时出现错误:
javax.servlet.ServletException: A MultiException has 1 exceptions. They are:
1. java.lang.NoClassDefFoundError: com/agent/MyAdviser
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:391)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
我的经纪人:
LOG.info("Before Agent Builder build !!!");
new AgentBuilder.Default()
.with(new AgentBuilder.InitializationStrategy.SelfInjection.Eager())
.type(is(MyClassToCatch.class))
.transform(
new AgentBuilder.Transformer.ForAdvice()
.include(MyAgent.class.getClassLoader())
.advice(ElementMatchers.any(), MyAdviser.class.getName())
)
.installOn(inst);
而 MyAdviser.class 是:
public class MyAdviser {
private static final Logger LOG = LoggerFactory.getLogger(MyAdviser.class);
@Advice.OnMethodEnter
public static void onEnterExit() {
LOG.info("INTERCEPTED BBB <<<>>> BBB");
}
问题是否与类加载器有关? BR,
Rafael 的解决方案有所帮助。
编辑:我也尝试拦截一个方法,然后直接调用它而不做任何更改,但我以这样的错误结束:
com.agent.DiscoveryAgent - On Error of : MyClassToCatch None of [net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@7815f1c, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@a193f70f, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@d6fdc355, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@66e2275b, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@19cb065f, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@4fc13971, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@aea74e0e, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@2ac04890, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@f5eef57c, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@e1b04a0f, net.bytebuddy.implementation.bind.annotation.TargetMethodAnnotationDrivenBinder$Record@f0de1c86] allows for delegation from public javax.ws.rs.core.Response MyClassToCatch.someMethod()
【问题讨论】:
标签: javaagents byte-buddy