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

Quarkus调用REST Client子资源抛出AbstractMethodError问题求助

问题根因

该问题由quarkus-rest-client-reactive扩展的原生限制导致:目前响应式REST Client扩展未实现MicroProfile REST Client规范中的子资源接口代理生成逻辑,你所使用的子资源嵌套写法仅在经典阻塞式REST Client扩展中支持,调用未实现的代理方法时就会抛出AbstractMethodError。

解决方案

提供两种适配方案,可根据业务场景选择:

方案1:切换为阻塞式REST Client(无需修改业务逻辑)

如果你的服务没有强响应式编程需求,直接替换依赖即可兼容原有写法:

  1. 移除构建配置中quarkus-rest-client-reactive相关依赖
  2. 引入经典REST Client依赖,Maven示例如下:
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-rest-client</artifactId>
</dependency>

替换后你现有子资源定义、调用逻辑均可直接正常运行。

方案2:保留响应式扩展,重构接口合并路径

如果必须使用响应式能力,直接将子资源路径合并到顶层接口即可,无需拆分两层接口:

package org.acme.example;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import io.smallrye.mutiny.Uni;
import java.util.List;

@RegisterRestClient
@Path("/api/foo")
public interface FoosService {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    Uni<List<Foo>> getAll();

    @GET
    @Path("/{id}")
    @Produces(MediaType.APPLICATION_JSON)
    Uni<Foo> getFooById(@PathParam("id") String id);
}

调用代码同步调整:

@Path("/bar")
public class BarResource {
    @RestClient
    FoosService client;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Uni<Foo> getBar() {
        return client.getFooById("bar");
    }
}

额外注意

你给出的调用代码存在笔误:接口定义为FoosService,但注入时错误使用了FoosResource类型,实际运行时需要修正类型匹配,否则会出现注入异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 16:00:04