对于注册到Eureka的微服务,可以通过服务发现来获得该服务的信息。
下面将介绍如何使用DiscoveryClient获取注册中心上的实例信息。
1、Controller中注入DiscoveryClient
@RestController
@Slf4j
public class PaymentController {
@Resource
private PaymentService paymentService;
@Resource
private DiscoveryClient discoveryClient;
@Value("${server.port}")
private String serverPort;
...
}
其中: