Peter Dongan
Peter Dongan

Reputation: 2306

Maven WebClient dependency errors (in Docker container)

I'm getting an error when I try to connect to a REST service using WebClient in Java Spring inside a Docker container. I was wondering if anyone can tell me what the problem is?

Runtime Error: java.lang.NoClassDefFoundError: org/springframework/http/client/reactive/ClientHttpConnector

Dependencies:

<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"]

Upvotes: 0

Views: 543

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42461

I don't think its really related to the fact that you're running in Docker. Probably the reason is the clash of spring versions. Out of the pom you've presented, spring boot 2.x works with spring 5.x jars, but you bring up 4.3.9.RELEASE of spring-web and webmvc.

Usually you should omit jar versions at all, and spring boot will add all the relevant transitive dependencies.

Another thing that might be problematic is that you're trying to use both webflux and webmvc. Its possible in spring boot, but think first whether its really what you need.

To see the exact versions - remove all the spring related dependencies and run mvn dependency:tree - you'll see which spring versions the tree will show.

Upvotes: 1

Related Questions