首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在Quarkus中进行REST调用时出错

尝试在Quarkus中进行REST调用时出错
EN

Stack Overflow用户
提问于 2021-03-03 11:54:21
回答 1查看 667关注 0票数 1

我正在尝试在我拥有的另一个服务上执行请求。我用来创建应用程序的指南是:

QUARKUS - Using the REST Client

QUARKUS - CDI Reference

QUARKUS - Workshop

我收到如下错误:

代码语言:javascript
复制
org.jboss.resteasy.spi.UnhandledException: java.lang.RuntimeException: Error injecting com.easy.ecomm.core.product.ProductClient com.easy.ecomm.core.cart.CartService.productClient

org.eclipse.microprofile.rest.client.RestClientDefinitionException: Parameters and variables don't match on interface com.easy.ecomm.core.product.ProductClient::findProductById

下面是类ProductClient

代码语言:javascript
复制
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@Path("products")
@RegisterRestClient(configKey = "products-api")
public interface ProductClient {

    @GET
    @Path("{id}")
    Product findProductById(String id);

}

下面是服务层:

代码语言:javascript
复制
import org.eclipse.microprofile.rest.client.inject.RestClient;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

@ApplicationScoped
public class CartService {

    @Inject
    @RestClient
    ProductClient productClient;

    public void addItem(String cartId, String productId, Integer amount){
        // Code to find the cart on a queue.
        Product product = findProduct(productId);
        cart.getItems().add(new CartItem(amount, product));
    }

    private Product findProduct(String productId) {
        return productClient.findProductById(productId);
    }
}

application.properties

代码语言:javascript
复制
products-api/mp-rest/url=http://localhost:8060
products-api/mp-rest/scope=javax.inject.Singleton

依赖项与我们在指南quarkus-rest-clientquarkus-rest-client-jackson上的依赖项相同

我已经尝试过的东西:

@RegisterRestClient中删除ConfigKey并使用application.properties上的完整路径,在我的POM.xml上添加Jandex插件,如here所述。

但还是没有成功。每次更改都会给出相同的错误消息。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-09 05:18:25

您忘记使用@PathParam注释path变量,这就是它无法实例化客户端的原因:

代码语言:javascript
复制
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import javax.ws.rs.PathParam;

@Path("products")
@RegisterRestClient(configKey = "products-api")
public interface ProductClient {

    @GET
    @Path("{id}")
    Product findProductById(@PathParam("id") String id);

}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66450546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档