久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Spring Cloud Consul的服務(wù)注冊(cè)與發(fā)現(xiàn)

瀏覽:3日期:2023-07-21 18:18:13
運(yùn)行Consul

以Windows為例,下載解壓后,以開(kāi)發(fā)模式運(yùn)行:

consul agent --dev

Spring Cloud Consul的服務(wù)注冊(cè)與發(fā)現(xiàn)

啟動(dòng)成功后,可以訪問(wèn)Consul提供的管理頁(yè)面,默認(rèn)端口為8500,頁(yè)面上顯示了已注冊(cè)服務(wù)的列表,包括它們的運(yùn)行狀況等信息。

Spring Cloud Consul的服務(wù)注冊(cè)與發(fā)現(xiàn)

服務(wù)注冊(cè)1.添加Spring Cloud Consul依賴(lài):

<dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency></dependencies>2.在服務(wù)配置文件中添加Consul配置:

spring: cloud: consul: host: localhost port: 85003.運(yùn)行消費(fèi)者和提供者服務(wù),Consul管理頁(yè)面將顯示對(duì)應(yīng)的服務(wù)信息:

Spring Cloud Consul的服務(wù)注冊(cè)與發(fā)現(xiàn)

服務(wù)發(fā)現(xiàn)

使用RestTemplate調(diào)用服務(wù)

@AutowiredRestTemplate restTemplate;public String getFirstProduct() { return this.restTemplate.getForObject('https://服務(wù)名/products/1', String.class);}

要使用RestTemplate別忘了加配置:

@Bean@LoadBalancedpublic RestTemplate restTemplate(){return new RestTemplate();}

以上就是Spring Cloud Consul的服務(wù)注冊(cè)與發(fā)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Spring Cloud Consul 服務(wù)注冊(cè)與發(fā)現(xiàn)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 利辛县| 水城县| 安龙县| 佳木斯市| 仙桃市| 麟游县| 泽州县| 哈尔滨市| 大埔区| 陇南市| 博罗县| 繁昌县| 文化| 许昌市| 乌兰察布市| 乌拉特后旗| 威海市| 拜城县| 定陶县| 固安县| 新密市| 南部县| 柳林县| 安溪县| 龙州县| 双柏县| 务川| 伊春市| 武义县| 泸州市| 炉霍县| 三穗县| 榆中县| 黄陵县| 泸水县| 田东县| 海阳市| 荣昌县| 长垣县| 报价| 临泽县|