-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Description
Describe the bug
In a Spring Boot 3.2.5 + Spring Cloud Alibaba 2023.0.1.0 project, using Spring Cloud Gateway with Nacos discovery results in:
java.lang.NoSuchMethodError: 'java.util.Set org.springframework.http.HttpHeaders.headerSet()'
at org.springframework.cloud.gateway.filter.headers.ForwardedHeadersFilter.filter(ForwardedHeadersFilter.java:99)
Expected behavior
The gateway should forward requests without throwing NoSuchMethodError.
Actually behavior
Gateway fails with the described error.
How to Reproduce
- Create a Spring Boot 3.2.5 project with Spring Cloud 2023.0.4 and Spring Cloud Alibaba 2023.0.1.0.
- Add a gateway module using
spring-cloud-starter-gatewayandspring-cloud-starter-alibaba-nacos-discovery. - Start Nacos server, register a simple service.
- Access any route through the gateway; observe the
NoSuchMethodError.
Root cause analysis:
The nacos-client-2.3.2.jar shades org.springframework.http.HttpHeaders without relocating the package, conflicting with the application's own Spring 6 classes.
Desktop
- OS: Windows 11
- JDK: 17.0.18
- Spring Boot: 3.2.5
- Spring Cloud: 2023.0.4
- Spring Cloud Alibaba: 2023.0.1.0
- Nacos Client: 2.3.2 (embedded in the starter)
Suggested fix:
- Avoid shading Spring classes, or if shading is necessary, relocate them (e.g.,
com.alibaba.nacos.shaded.org.springframework.http) to prevent conflicts. - Upgrade the shaded Spring version to 6.x to maintain method compatibility.
Additional context
This issue is resolved in later versions (Nacos Client 2.4.3) where the shading is no longer present.