所以我有一个 springboot 应用程序,我正在将其从 WAS 迁移到 springboot 设置。我有几个必须配置的 JSP。为了适应这些,我添加了以下依赖项:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>9.0.22</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>
该应用程序已附带以下依赖项,该依赖项正在整个应用程序中使用:
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm-jaxrpc-client</artifactId>
<version>6.0</version>
</dependency>
我面临的问题是这两个依赖项(jaxrpc-client 和 tomcat-embed-jasper)中都有 javax.servlet.ServletContext 类,这会导致以下错误:
The method's class, javax.servlet.ServletContext, is available from the following locations:
jar:file:/C:/Users/.m2/repository/com/ibm/com.ibm-jaxrpc-client/6.0/com.ibm-jaxrpc-client-6.0.jar!/javax/servlet/ServletContext.class
jar:file:/C:/Users/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.30/tomcat-embed-core-9.0.30.jar!/javax/servlet/ServletContext.class
It was loaded from the following location:
file:/C:/Users/.m2/repository/com/ibm/com.ibm-jaxrpc-client/6.0/com.ibm-jaxrpc-client-6.0.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of javax.servlet.ServletContext
我无法删除任何这些依赖项。 jaxrpc-client 在代码中已经在太多地方被引用,我需要 tomcat-embed-jasper 来渲染我的 jsp 页面。我无法排除 ServletContext 类,因为它不是依赖项(如果我对排除的概念没有理解错的话)。请帮助解决此问题。
最佳答案
我不熟悉 IBM 的 jaxrpc 客户端,但我假设,当尝试加载应用程序时,您在运行时会遇到此异常。
在这种情况下,请考虑以下方法:
使用另一个 jax-rpc 客户端库
考虑使用不同的类加载器加载使用此库的代码(您必须为此创建一个类加载器)以避免冲突
对第二个选项的解释。您可以使用 Spring Boot 类加载器“玩”(覆盖特定类的加载顺序),如 this article 中所述。
我知道,这个答案太笼统了,但希望它仍然有帮助。 第一个解决方案是迄今为止我能想到的最简单的方法。
第二种解决方案是可行的,但是它很大程度上取决于使用 jax rpc 客户端的代码的加载和使用方式。
关于javax.servlet.ServletContext 正在从 Spring Boot 应用程序中的多个依赖项加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60483242/