Spring Cloud 获取注册中心所有服务以及服务下的所有实例

在任意客户端填写如下代码:

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;

/**
 * 获取每一个服务下面实例
 * 测试时,可以使用多个端口启动服务实例
 */
@Autowired
private DiscoveryClient discoveryClient;

@GetMapping("/service_url")
public Map<String, List<ServiceInstance>> serviceUrl() {
    Map<String, List<ServiceInstance>> msl = new HashMap<>();
    List<String> services = discoveryClient.getServices();
    for (String service : services) {
        List<ServiceInstance> sis = discoveryClient.getInstances(service);
        msl.put(service, sis);
    }
    return msl;
}
上一篇 Spring Cloud Feign传递map对象和多媒体文件
下一篇 Spring Boot国际化MessageSource使用
目录
文章列表
1 阿里巴巴Canal之Canal Admin
阿里巴巴Canal之Canal Admin
2
Redis HyperLogLog
Redis HyperLogLog
3
elastic-job-lite原理与监控平台搭建
elastic-job-lite原理与监控平台搭建
4
Makefile反过滤函数filter-out
Makefile反过滤函数filter-out
5
pip3异常No module named 'pip._internal'
pip3异常No module named 'pip._internal'
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。