Spring Cloud:服务发现Discovery
一.
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; } }
输出结果 控制台:
输出结果 浏览器: