@RequestHeader overrides @PathVariable with the same name

未关闭
#1,465 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@rajeshvasa 已经在做这个了。

开始于 2026年11月18日。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
64/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java, spring
领域
api, backend

调研方向

Start by tracing how Spring Cloud OpenFeign resolves @PathVariable and @RequestHeader parameters when they share a name, then find the related request mapping tests. Reproduce the sample request and verify that the URI uses 1 for {id} while the header remains A. Add a regression test for the behavior and run the relevant tests.

由索引模型根据 Issue 内容生成。

描述

waiting-for-triage

Describe the bug

If @RequestHeader and @PathVariable have the same name, the header value is inserted to the uri template instead of the path variable.

Spring HTTP Service Clients does not have this problem.

Sample

interface TestApi {
    @GetMapping(value = "/test/{id}")
    void test(@PathVariable Integer id, @RequestHeader("id") String headerId);
}

@FeignClient(name = "testClient", url = "http://localhost:8080")
interface TestClient extends TestApi {
}

@RestController
class TestController implements TestApi {
    public void test(Integer id, String headerId) {
    }
}

@SpringBootApplication
@EnableFeignClients
class SampleApplication implements ApplicationRunner {

    @Autowired
    private TestClient testClient;

    public void run(ApplicationArguments args) {
        // this requests test/A instead of test/1
        testClient.test(1, "A");
    }

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

Dependencies:

    implementation(platform("org.springframework.boot:spring-boot-dependencies:4.1.2"))
    implementation(platform("org.springframework.cloud:spring-cloud-dependencies:2025.1.4"))
    implementation(platform("io.github.openfeign:feign-bom:13.18"))
    implementation("org.springframework.boot:spring-boot-starter-webmvc")
    implementation("org.springframework.cloud:spring-cloud-starter-openfeign")

If using Spring HTTP Service Clients, the problem is not reproduced:

interface TestClient {
    @GetExchange("/test/{id}")
    void test(@PathVariable Integer id, @RequestHeader("id") String headerId);
}
主要语言
Java
星标
1.3k
派生
834
平均合并
3 天 6 小时
30 天内合并 PR
14

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

spring-cloud/spring-cloud-openfeign 的其他 Issue

查看 spring-cloud/spring-cloud-openfeign 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。