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

     输出结果 控制台:

     输出结果 浏览器:

     

  • 相关阅读:
    tar.gz文件
    Ruby Symbol
    Ruby表达式
    Linux相关命令
    Ruby file
    Tomcat优化
    修改Linux文件的所属用户和组
    Ruby String
    Ruby Range
    HTML5开源专业图像处理引擎——AlloyImage(简称AI)
  • 原文地址:https://www.cnblogs.com/wwjj4811/p/13616218.html
Copyright © 2020-2023  润新知