【发布时间】:2021-08-06 19:02:49
【问题描述】:
我正在为我的 API 使用 Spring Boot。我正在重写我的 API,以采用微服务架构。
我有 2 节课:
1) 产品
2) 成分
我的代码:
这是我的产品类:
public class Product{
private String name;
@ElementCollection
private List<Long> productIngredients = new ArrayList<>(); //Ingredient
private Double quantity = 0.0;
private Double productCost = 0.0;
}
这是我的Ingredient类:
public class Ingredient{
private String name;
private String unit;
private Double quantity = 0.0;
}
在 Product 微服务中,我正在对 Ingredient 微服务进行 API 调用:
// Making a call to the Ingredients microservice from the product microservice
WebClient myWebClient = WebClient.create("http://localhost:8090/api");
@GetMapping("/ingredients/get")
public Flux<Product> getIngredients(){
return myWebClient
.get()
.uri("/ingredients/ingredient/list")
.retrieve()
.bodyToFlux(Product.class);
}
但是,上面的 getIngredients() 方法不起作用。
我的问题:
我想从成分微服务中获取数据,但是,我收到以下错误:
"error": "内部服务器错误", “trace”:“org.springframework.web.reactive.function.client.WebClientRequestException:连接被拒绝:没有更多信息:localhost/127.0.0.1:80;嵌套异常是io.netty.channel.AbstractChannel$AnnotatedConnectException:连接被拒绝:没有更多信息:localhost/127.0.0.1:80\r\n\tat org.springframework.web.reactive.function.client.ExchangeFunctions$DefaultExchangeFunction.lambda$wrapException$9(ExchangeFunctions.java:141)\r\n\tSuppressed : reactor.core.publisher.FluxOnAssembly$OnAssemblyException: \n在以下站点观察到错误:\n\t|_ checkpoint ⇢ 请求获取 http://localhost/api/components/component/list [DefaultWebClient ]\n堆栈跟踪:\r\n\t\tat org.springframework.web.reactive.function.client.
【问题讨论】:
标签: java spring spring-boot spring-mvc spring-data-jpa