Loading

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;
    }
}

 输出结果 控制台:

 

 输出结果 浏览器:

 

 

posted @ 2020-09-04 21:13  秋风飒飒吹  阅读(1140)  评论(0编辑  收藏  举报