【发布时间】:2021-10-02 21:20:05
【问题描述】:
编辑:问题是quarkus-rest-client-reactive,请参阅我的回答。
根据我对 Quarkus 中可用的 MicroProfile REST 客户端的理解,我应该能够在我的 REST 客户端界面中定义子资源,这将允许我像这样将资源嵌套在彼此之下。
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;
@RegisterRestClient
@Path("/api/foo")
public interface FoosService {
@GET
@Produces(MediaType.APPLICATION_JSON)
Uni<List<Foo>> getAll();
@Path("/{id}")
FooService foo(@PathParam("id") String id);
}
public interface FooService {
@GET
@Produces(MediaType.APPLICATION_JSON)
Uni<Foo> toRepresentation();
}
但是,当我在代码中注入和调用客户端接口时,它会在 client.foo("bar").toRepresentation() 调用上引发 AbstractMethodError。
@Path("/bar")
public class BarResource {
@RestClient
FoosResource client;
@GET
@Produces(MediaType.APPLICATION_JSON)
public Foo getBar() {
return client.foo("bar").toRepresentation();
}
}
我对此的所有研究似乎都表明这是可能的,但 Quarkus 没有显示客户端子资源的具体示例。
【问题讨论】:
-
@LucaBassoRicci Keycloak Admin API Client 是使用包含子资源的客户端代理框架的 RESTEasy 客户端的一个很好的示例(该客户端中的 RESTEasy 版本是 3.13.2,而最新的 Quarkus 版本使用4.6.1,但没有任何 RESTEasy 更改日志提及相关行为的任何更改。)
-
我假设你有复制粘贴错误,但两个接口都命名为 FooService
-
你弄明白了吗?
标签: java resteasy quarkus quarkus-rest-client