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

The error “spring mvc found on classpath, which is incompatible with spring cloud gateway” occurs when there is a conflict between the Spring MVC library and the Spring Cloud Gateway library. Spring MVC is a framework for building web applications using the Model-View-Controller design pattern, while Spring Cloud Gateway is a library for building API gateways.

When we include both libraries in our project, they may have conflicting dependencies or classes with the same name, leading to this error. To resolve this, we need to exclude the Spring MVC library from the classpath when using Spring Cloud Gateway.

Here’s an example of how to exclude the Spring MVC library in a Maven project using the exclusions tag in the dependency declaration:


    <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 are excluding the spring-boot-starter-web artifact, which includes the Spring MVC library, from the spring-cloud-starter-gateway dependency. By doing this, we ensure that only the necessary dependencies for Spring Cloud Gateway are included and there are no conflicts with Spring MVC.

You may need to adjust the specific artifact and version names based on your project’s configuration and dependencies.

Read more

Leave a comment