【发布时间】:2019-08-12 19:50:40
【问题描述】:
我有一个 ShopMicroService、一个 CustomerMicroService 和一个 CartMicroService。
ShopMicroService 应该作为 API 网关工作,并且应该能够控制所有其他服务。它们通过 Netflix Zuul 连接和路由。
我希望能够打电话给例如localhost:8080/list,并查看来自 CustomerMicroService 和 CartMicroService 的数据。但我也无法在我的 ShopController 中返回两个方法。我该如何解决这个问题?
Shop2CartConnector:
@FeignClient("cartmicroservice")
public interface Shop2CartConnectorRequester {
@GetMapping("/list")
public List<?> getCart();
Shop2CustomerConnector:
@FeignClient("customermicroservice")
public interface Shop2CustomerConnectorRequester {
@GetMapping("/list")
public List<?> getCustomer();
ShopController:
@ComponentScan
@RestController
public class ShopController {
final Shop2CustomerConnectorRequester shop2CustomerConnectorRequester;
final Shop2CartConnectorRequester shop2CartConnectorRequester;
@Autowired
public ShopController(Shop2CustomerConnectorRequester shop2CustomerConnectorRequester,
Shop2CartConnectorRequester shop2CartConnectorRequester) {
this.shop2CustomerConnectorRequester = shop2CustomerConnectorRequester;
this.shop2CartConnectorRequester = shop2CartConnectorRequester;
}
@GetMapping("/getCustomer")
public List<?> getCustomer() {
return shop2CustomerConnectorRequester.getCustomer();
}
@GetMapping("/getCart")
public List<?> getCart() {
return shop2CartConnectorRequester.getCart();
}
我已经尝试只调用一种方法并使用两种方法,但它仍然只显示我返回的列表。
【问题讨论】:
标签: java spring-data-jpa netflix-eureka netflix-zuul spring-cloud-feign