我正在为我的 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;
}
这是我的成分类:
public class Ingredient{
private String name;
private String unit;
private Double quantity = 0.0;
}
在产品微服务中,我正在对成分微服务进行 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() 方法不起作用。
我的问题:
我想从成分微服务中获取数据,但是,我收到以下错误:
“错误”:“内部服务器错误”,“跟踪”:“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 ⇢ Request to GET http://localhost /api/components/component/list [DefaultWebClient]\n堆栈跟踪:\r\n\t\tat org.springframework.web.reactive.function.client。