一.
application主應用class:
@EnableEurekaClient
@SpringBootApplication
@EnableDiscoveryClient
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class,args);
}
}
二.
@Slf4j
@RestController
public class OrderController {
@Resource
private DiscoveryClient discoveryClient;
@GetMapping("/payment/discovery")
public Object discovery(){
List<String> services = discoveryClient.getServices();
for(String ele : services){
log.info(ele);
}
log.info("=======================");
List<ServiceInstance> instances = discoveryClient.getInstances("CLOUD-PAYMENT-SERVICE");
for (ServiceInstance instance : instances) {
log.info(instance.getServiceId());
log.info(instance.getHost());
log.info(instance.getUri().toString());
}
return this.discoveryClient;
}
}
輸出結果 控制台:

輸出結果 瀏覽器:

