![](/img/trans.png)
[英]Spring Boot Microservice depends on another Microservice in Jenkins
[英]Spring Boot - fetching data from another microservice
我正在為我的 API 使用 Spring 引導。 我正在重寫我的 API,以采用微服務架構。
我有 2 節課:
1) 產品
2) 成分
我的代碼:
這是我的產品class:
public class Product{
private String name;
@ElementCollection
private List<Long> productIngredients = new ArrayList<>(); //Ingredient
private Double quantity = 0.0;
private Double productCost = 0.0;
}
這是我的成分class:
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.ExchangeFunction(9$Functions.client.ExchangeFunctionFunction java:141)\r\n\tSuppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: \n在以下站點觀察到錯誤:\n\t|_ checkpoint ⇢ Request to GET Z80791B3AE7002FACB88C2468876D /api/components/component/list [DefaultWebClient]\n堆棧跟蹤:\r\n\t\tat org.springframework.web.reactive.ZC1C425268E68385D1AB5074C 17A94F14Z.client。
Connection refused: no further information: localhost/127.0.0.1:80
,異常說:
myWebClient
實例是配置了正確的 URL 的實例嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.