class 在存在 2 个版本的库时按需加载 tomcat?

class loading in tomcat on demand when 2 versions of a lib are present?

我在网上搜索了很多资源。但我仍然找不到能够准确解决我的问题的特定资源。

在tomcat中,是否有class中的任何命令在启动时加载。想象一下这样的情况。

我在 webapps 中有 myApp.war 文件。在那个 war 里面,我有一些库(比如 mylib-2.5.jar 捆绑在里面 )。想象一下,我还在 /lib 文件夹中放置了不同版本的相同库(比如 mylib-2.8.jar) .

因此,当我启动我的应用程序并调用特定端点时,哪个库(版本)将有机会通过 class 加载程序(按需)加载到 JVM 中?

库冲突的可能性有多大?原因是什么?

来自@GyroGearless 发布的 link

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:

•Bootstrap classes of your JVM

•/WEB-INF/classes of your web application

•/WEB-INF/lib/*.jar of your web application

•System class loader classes (described above)

•Common class loader classes (described above)

If the web application class loader is configured with <Loader delegate="true"/> then the order becomes:

•Bootstrap classes of your JVM

•System class loader classes (described above)

•Common class loader classes (described above)

•/WEB-INF/classes of your web application

•/WEB-INF/lib/*.jar of your web application

如果 classloader 需要加载 class X 那么一旦它在一个地方找到它就不会在任何其他地方寻找它。 如果您将一个版本的依赖项(例如 MySQL 驱动程序)放置到 $JAVA_HOME/jre/lib/ext 并将另一个版本放置到 /WEB-INF/lib

中,则可能发生 Lib 冲突