I am using Spring Boot for my API. I am rewriting my API, to adopt the microservices architecture.
I have 2 classes:
1) Product
2) Ingredient
My Code:
Here is my Product 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;
}
Here is my Ingredient class:
public class Ingredient{
private String name;
private String unit;
private Double quantity = 0.0;
}
In the Product microservice, I am doing an API call to the Ingredient microservice:
// 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);
}
However, the above getIngredients() method is not working.
My Question:
I want to fetch data from the Ingredient microservice, however, I get the following error:
"error": "Internal Server Error", "trace": "org.springframework.web.reactive.function.client.WebClientRequestException: Connection refused: no further information: localhost/127.0.0.1:80; nested exception is io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: 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: \nError has been observed at the following site(s):\n\t|_ checkpoint ⇢ Request to GET http://localhost/api/components/component/list [DefaultWebClient]\nStack trace:\r\n\t\tat org.springframework.web.reactive.ZC1C425268E68385D1AB5074C 17A94F14Z.client.
Connection refused: no further information: localhost/127.0.0.1:80
, exception says that:
myWebClient
instance is the one that is configured with the correct URL?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.