Skip to content

Nacos Client 2.3.2 shades org.springframework.http.HttpHeaders causing NoSuchMethodError with Spring Boot 3.2.x #14596

@Wrathur

Description

@Wrathur

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

  1. Create a Spring Boot 3.2.5 project with Spring Cloud 2023.0.4 and Spring Cloud Alibaba 2023.0.1.0.
  2. Add a gateway module using spring-cloud-starter-gateway and spring-cloud-starter-alibaba-nacos-discovery.
  3. Start Nacos server, register a simple service.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions