使用bytebuddy对springboot 应用进行instrument的时候,会原本正常的springboot 应用有class not found的情况。

网上能看到基本都是说双亲机制导致的问题,有些提供了很复杂的解决方法。

但经过测试发现使用appendToBootstrapClassLoaderSearch 把相关class
导入class path即可,参考代码如下。

 //  instrumentation.appendToSystemClassLoaderSearch(jarFile);
        //spring bott 使用bootStrapClassLoader
        //The agent should take care to ensure that the JAR does not contain any classes or resources other than those to be defined by
        // the bootstrap class loader for the purpose of instrumentation.
       instrumentation.appendToBootstrapClassLoaderSearch(jarFile);
Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐