Compatibilidad de versiones entre Spring Boot y Spring Cloud
| Framework | Versión |
|---|---|
| Spring Boot | 2.3.12.RELEASE |
| Spring Cloud | Hoxton.SR1 |
Configuración de dependencias en pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.12.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Archivo de configuración (application.yml)
server:
port: 8700
spring:
application:
name: api-gateway-service
cloud:
gateway:
routes:
- id: user_service_route
uri: http://localhost:8081/
predicates:
- Path=/api/users/**
filters:
- name: StripPrefix
args:
parts: 1
Problema de conflicto de dependencias
La aparición de spring-boot-starter-web en el classpath junto con Spring Cloud Gateway genera un error de incompatibilidad, ya que el starter de Gateway ya incluye internamente spring-boot-starter-webflux. Esta combinación provoca excepciones durante el arranque de la aplicación:
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.
Parameter 0 of method modifyRequestBodyGatewayFilterFactory in org.springframework.cloud.gateway.config.GatewayAutoConfiguration required a bean of type 'org.springframework.http.codec.ServerCodecConfigurer' that could not be found.
Etsrategias de solución
Existen dos alternativas principales para resolver el conflicto:
1. Eliminación completa del starter web:
<!-- No incluir spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
2. Exclusión del starter webflux dentro de una dependencai web explícita:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</exclusion>
</exclusions>
</dependency>