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

Quarkus 3.10.2 Rest Client报错:仅允许单个Body参数

问题解决:Quarkus 3.10.2升级后REST Client报错“can only have a single body parameter: token”

问题原因

Quarkus 3.10.2升级了MicroProfile Rest Client的底层实现,对REST客户端方法的参数校验规则更严格:

  • GET请求不允许存在body参数,所有参数必须明确标注对应的参数类型注解(如@PathParam、@QueryParam、@HeaderParam)
  • 你的代码中Set<String> pc没有添加任何参数注解,被框架默认识别为body参数;同时@PathParam("userId")对应的路径/aa/productNames里没有{userId}占位符,注解无效,进一步触发参数解析异常

解决方案

  1. 给未注解的参数pc添加正确的参数类型注解(根据实际接口需求选择,以下以查询参数为例)
  2. 修正userId的参数注解:要么在路径中添加{userId}占位符,要么改为@QueryParam/@HeaderParam
  3. 移除token上的@NotBody注解(@ClientHeaderParam引用的参数会被自动识别为非body参数,无需额外标注)

修改后的代码示例

import io.quarkus.vertx.web.Body;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.QueryParam;

import org.eclipse.microprofile.rest.client.annotation.ClientHeaderParam;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import java.util.List;
import java.util.Set;


@RegisterRestClient(configKey = "aa-api")
@RegisterClientHeaders(RequestUUIDHeaderFactory.class)
public interface HttpProductService {
    @GET
    // 如果userId是路径参数,就改成@Path("/aa/productNames/{userId}")
    @Path("/aa/productNames")
    @ClientHeaderParam(name = "Authorization", value = "Bearer {token}")
    List<PDto> getProductNames(@QueryParam("userId") String uid,
                               String token,
                               @QueryParam("pc") Set<String> pc);
}

额外说明

如果pc需要以多值查询参数的形式传递(如?pc=val1&pc=val2),Quarkus REST Client会自动将Set<String>类型的参数解析为多值查询参数,无需额外配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 15:12:32