{"id":898,"date":"2023-03-11T06:56:59","date_gmt":"2023-03-10T22:56:59","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=898"},"modified":"2023-04-29T15:54:03","modified_gmt":"2023-04-29T07:54:03","slug":"spring-cloud-obtains-all-services-in-registry-and-all-instances-under-services","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/11\/spring-cloud-obtains-all-services-in-registry-and-all-instances-under-services\/","title":{"rendered":"Spring Cloud \u83b7\u53d6\u6ce8\u518c\u4e2d\u5fc3\u6240\u6709\u670d\u52a1\u4ee5\u53ca\u670d\u52a1\u4e0b\u7684\u6240\u6709\u5b9e\u4f8b"},"content":{"rendered":"<p>\u5728\u4efb\u610f\u5ba2\u6237\u7aef\u586b\u5199\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">import org.springframework.cloud.client.ServiceInstance;\nimport org.springframework.cloud.client.discovery.DiscoveryClient;\n\n\/**\n * \u83b7\u53d6\u6bcf\u4e00\u4e2a\u670d\u52a1\u4e0b\u9762\u5b9e\u4f8b\n * \u6d4b\u8bd5\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u7aef\u53e3\u542f\u52a8\u670d\u52a1\u5b9e\u4f8b\n *\/\n@Autowired\nprivate DiscoveryClient discoveryClient;\n\n@GetMapping(&quot;\/service_url&quot;)\npublic Map&lt;String, List&lt;ServiceInstance&gt;&gt; serviceUrl() {\n    Map&lt;String, List&lt;ServiceInstance&gt;&gt; msl = new HashMap&lt;&gt;();\n    List&lt;String&gt; services = discoveryClient.getServices();\n    for (String service : services) {\n        List&lt;ServiceInstance&gt; sis = discoveryClient.getInstances(service);\n        msl.put(service, sis);\n    }\n    return msl;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4efb\u610f\u5ba2\u6237\u7aef\u586b\u5199\u5982\u4e0b\u4ee3\u7801\uff1a import org.springframework.cloud.client.S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[],"class_list":["post-898","post","type-post","status-publish","format-standard","hentry","category-spring-cloud"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=898"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/898\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}