文章目录
bytebuddy在项目和javaagent都被使用的,但是版本冲突了,优先加载应用程序依赖的包,导致agent中缺少一些方法。
重命名包
maven可以将依赖包也打到jar包里面,并且修改类的路径。这样类加载时就不会有冲突了。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<includes>
<include>javassist:javassist:jar:</include>
<include>net.bytebuddy:byte-buddy:jar:</include>
<include>net.bytebuddy:byte-buddy-agent:jar:</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>net.bytebuddy</pattern>
<shadedPattern>my.net.bytebuddy</shadedPattern>
</relocation>
</relocations>
</configuration>
</plugin>