{"id":8926,"date":"2023-11-28T20:48:07","date_gmt":"2023-11-28T12:48:07","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8926"},"modified":"2023-12-06T16:09:40","modified_gmt":"2023-12-06T08:09:40","slug":"springcloud-zhong-duo-ge-xiao-fei-zhe-diao-yong-to","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/springcloud-zhong-duo-ge-xiao-fei-zhe-diao-yong-to\/","title":{"rendered":"SpringCloud\u4e2d\u591a\u4e2a\u6d88\u8d39\u8005\u8c03\u7528\u540c\u4e00\u4e2a\u63a5\u53e3\uff0ceruka\u9ed8\u8ba4\u7684\u5206\u914d\u65b9\u5f0f\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p>\u5728Spring Cloud\u4e2d\uff0c\u5f53\u591a\u4e2a\u670d\u52a1\u6d88\u8d39\u8005\u540c\u65f6\u8c03\u7528\u540c\u4e00\u4e2a\u670d\u52a1\u63d0\u4f9b\u8005\u65f6\uff0cEureka\u9ed8\u8ba4\u91c7\u7528\u7684\u662f\u57fa\u4e8e\u8d1f\u8f7d\u5747\u8861\u7684\u670d\u52a1\u8c03\u7528\u3002Eureka\u901a\u8fc7\u670d\u52a1\u6ce8\u518c\u548c\u670d\u52a1\u53d1\u73b0\u6765\u7ef4\u62a4\u670d\u52a1\u5b9e\u4f8b\u7684\u4fe1\u606f\uff0c\u5e76\u4e14\u652f\u6301\u8d1f\u8f7d\u5747\u8861\u673a\u5236\uff0c\u4f7f\u5f97\u670d\u52a1\u6d88\u8d39\u8005\u80fd\u591f\u5728\u591a\u4e2a\u670d\u52a1\u5b9e\u4f8b\u4e4b\u95f4\u8fdb\u884c\u5747\u8861\u7684\u8bf7\u6c42\u5206\u53d1\u3002<\/p>\n<p>Eureka\u7684\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u4e3b\u8981\u4f53\u73b0\u5728\u670d\u52a1\u6d88\u8d39\u8005\u901a\u8fc7\u670d\u52a1\u540d\u8c03\u7528\u670d\u52a1\u63d0\u4f9b\u8005\u65f6\u3002\u5f53\u670d\u52a1\u6d88\u8d39\u8005\u901a\u8fc7\u670d\u52a1\u540d\u53d1\u8d77\u8bf7\u6c42\u65f6\uff0cEureka\u4f1a\u4ece\u53ef\u7528\u7684\u670d\u52a1\u5b9e\u4f8b\u4e2d\u9009\u62e9\u4e00\u4e2a\uff0c\u4ee5\u5b9e\u73b0\u8bf7\u6c42\u7684\u5206\u53d1\u548c\u8d1f\u8f7d\u5747\u8861\u3002\u8fd9\u79cd\u8d1f\u8f7d\u5747\u8861\u65b9\u5f0f\u662f\u9ed8\u8ba4\u7684\u884c\u4e3a\uff0c\u65e0\u9700\u989d\u5916\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u5728Spring Cloud\u4e2d\u4f7f\u7528Eureka\u8fdb\u884c\u670d\u52a1\u6ce8\u518c\u3001\u53d1\u73b0\u548c\u8d1f\u8f7d\u5747\u8861\uff1a<\/p>\n<ol>\n<li><strong>\u670d\u52a1\u63d0\u4f9b\u8005\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-java\">@SpringBootApplication\n@EnableEurekaServer\npublic class EurekaServerApplication {\n    public static void main(String[] args) {\n        SpringApplication.run(EurekaServerApplication.class, args);\n    }\n}\n<\/code><\/pre>\n<ol start=\"2\">\n<li><strong>\u670d\u52a1\u6d88\u8d39\u8005\uff1a<\/strong><\/li>\n<\/ol>\n<pre><code class=\"language-java\">@SpringBootApplication\n@EnableDiscoveryClient\npublic class ConsumerApplication {\n    public static void main(String[] args) {\n        SpringApplication.run(ConsumerApplication.class, args);\n    }\n\n    @RestController\n    public class MyController {\n\n        @Autowired\n        private RestTemplate restTemplate;\n\n        @GetMapping(&quot;\/invoke-service&quot;)\n        public String invokeService() {\n            \/\/ \u901a\u8fc7\u670d\u52a1\u540d\u8c03\u7528\u670d\u52a1\uff0cEureka\u4f1a\u8fdb\u884c\u8d1f\u8f7d\u5747\u8861\n            String result = restTemplate.getForObject(&quot;http:\/\/service-provider\/api\/resource&quot;, String.class);\n            return &quot;Result: &quot; + result;\n        }\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c<code>ConsumerApplication<\/code>\u4e2d\u7684<code>invokeService<\/code>\u65b9\u6cd5\u901a\u8fc7<code>RestTemplate<\/code>\u53d1\u8d77\u5bf9<code>service-provider<\/code>\u670d\u52a1\u7684\u8bf7\u6c42\uff0c\u800c\u4e0d\u662f\u6307\u5b9a\u5177\u4f53\u7684\u670d\u52a1\u5b9e\u4f8b\u5730\u5740\u3002Eureka\u4f1a\u81ea\u52a8\u4ece\u53ef\u7528\u7684\u670d\u52a1\u5b9e\u4f8b\u4e2d\u9009\u62e9\u4e00\u4e2a\uff0c\u4ee5\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n<p>\u9700\u8981\u786e\u4fdd\u5728\u670d\u52a1\u63d0\u4f9b\u8005\u548c\u670d\u52a1\u6d88\u8d39\u8005\u7684<code>pom.xml<\/code>\u6587\u4ef6\u4e2d\u5f15\u5165\u4e86\u76f8\u5e94\u7684Eureka\u4f9d\u8d56\uff0c\u5982<code>spring-cloud-starter-eureka-server<\/code>\u548c<code>spring-cloud-starter-netflix-eureka-client<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Spring Cloud\u4e2d\uff0c\u5f53\u591a\u4e2a\u670d\u52a1\u6d88\u8d39\u8005\u540c\u65f6\u8c03\u7528\u540c\u4e00\u4e2a\u670d\u52a1\u63d0\u4f9b\u8005\u65f6\uff0cEureka\u9ed8\u8ba4\u91c7\u7528\u7684\u662f\u57fa\u4e8e\u8d1f\u8f7d\u5747\u8861 [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"class_list":["post-8926","post","type-post","status-publish","format-standard","hentry","category-springcloud"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=8926"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8926\/revisions"}],"predecessor-version":[{"id":16676,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8926\/revisions\/16676"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8926"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}