Spring mvc found on classpath, which is incompatible with spring cloud gateway.

When you encounter the error “spring mvc found on classpath, which is incompatible with spring cloud gateway,” it means that you have both Spring MVC and Spring Cloud Gateway dependencies in your project, and they are conflicting with each other.

Spring MVC is a full-featured framework for building web applications using the Model-View-Controller architectural pattern. On the other hand, Spring Cloud Gateway is a lightweight, programmable gateway that routes HTTP requests to different services.

The error occurs because both Spring MVC and Spring Cloud Gateway provide similar functionality for handling web requests and conflicts arise between their components on the classpath. To resolve this issue, you need to exclude the Spring MVC transitive dependency from the Spring Cloud Gateway dependency.

Here is an example of how to exclude the Spring MVC dependency when using Spring Cloud Gateway in a Maven project:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Hoxton.SR9</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
    <exclusions>
      <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
</dependencies>

In this example, we specify the version of Spring Cloud dependencies using the dependencyManagement section. Then, we include the Spring Cloud Gateway dependency with the exclusion of the Spring Boot Starter Web dependency, which includes Spring MVC. This exclusion removes the conflicting Spring MVC dependency from Spring Cloud Gateway, resolving the compatibility issue.

Related Post

Leave a comment