当我试图在Docker容器中使用Java Spring中的WebClient连接到REST服务时,我得到了一个错误。我想知道有没有人能告诉我问题出在哪里?
运行时错误:java.lang.NoClassDefFoundError: org/springframework/http/client/reactive/ClientHttpConnector
依赖关系:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-webflux -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>2.4.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.projectreactor.netty/reactor-netty -->
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>1.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-core -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.4.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.9.RELEASE</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>Dockerfile:
FROM tomcat:8-jre8
RUN ["rm", "-rf", "/usr/local/tomcat/webapps/ROOT"]
COPY mvctest.war /usr/local/tomcat/webapps/ROOT.war
CMD ["catalina.sh", "run"]发布于 2021-05-06 18:04:41
我不认为这真的与你在Docker中运行的事实有关。原因可能是spring版本之间的冲突。在您所介绍的pom中,spring boot 2.x可以与spring 5.x jars一起工作,但是您会引出4.3.9.RELEASE of spring-web和webmvc。
通常,您应该完全忽略jar版本,spring boot将添加所有相关的传递依赖项。
另一件可能有问题的事情是,你试图同时使用webflux和webmvc。这是可能的,但首先考虑它是否真的是你需要的。
要查看确切的版本-删除所有与spring相关的依赖项并运行mvn dependency:tree -您将看到树将显示哪些spring版本。
https://stackoverflow.com/questions/67415807
复制相似问题