You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

启动SpringBoot应用遇FeignClient错误:url不可为绝对路径

问题解决:FeignClient启动报错url values must be not be absolute

错误原因

你在@GetMapping注解里写了绝对URL(https://somehost.ru/{id}/orders),但Spring Cloud Feign要求@GetMapping的路径必须是相对路径,不能包含完整域名,这就是启动报错的核心原因。

解决方案

分两种场景处理:

场景1:调用外部第三方服务(somehost.ru是外部地址)

把域名部分移到@FeignClient的url属性中,@GetMapping只保留相对路径:

@FeignClient(name = "producer-service", url = "https://somehost.ru")
@Headers("Content-Type: application/json")
interface MarketServiceFeign {

    @GetMapping("/{id}/orders")
    fun getUserDevices(
            @PathVariable id: String,
    ): ResponseEntity<List<UserOrder>>

}

场景2:调用集群内的producer-service微服务

直接去掉域名,只用相对路径,Feign会通过服务发现自动找到集群内的producer-service实例:

@FeignClient(name = "producer-service")
@Headers("Content-Type: application/json")
interface MarketServiceFeign {

    @GetMapping("/{id}/orders")
    fun getUserDevices(
            @PathVariable id: String,
    ): ResponseEntity<List<UserOrder>>

}

为什么之前的尝试无效

  • @RequestLine是原生Feign的注解,和Spring Cloud封装的@FeignClient不兼容,所以无法解决问题;
  • 替换@Param只是参数注解的变更,没解决绝对URL的核心问题;
  • 把https改成http还是绝对URL,本质问题没修正,报错自然不会消失。

内容的提问来源于stack exchange,提问作者JavaSash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 09:20:25