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

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

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

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

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

consul agent --dev

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

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

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

服務(wù)注冊1.添加Spring Cloud Consul依賴:

<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īng)的服務(wù)信息:

Spring Cloud Consul的服務(wù)注冊與發(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ù)注冊與發(fā)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Spring Cloud Consul 服務(wù)注冊與發(fā)現(xiàn)的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 老河口市| 茂名市| 吉木萨尔县| 黎城县| 尤溪县| 历史| 东阳市| 济阳县| 西华县| 江陵县| 安远县| 成武县| 赤峰市| 哈尔滨市| 普陀区| 云南省| 讷河市| 措美县| 平顶山市| 深泽县| 巴楚县| 柘城县| 库尔勒市| 大宁县| 浏阳市| 定边县| 太原市| 保山市| 新河县| 陆川县| 乃东县| 修文县| 时尚| 乌兰浩特市| 平顺县| 和平区| 木里| 澜沧| 屯门区| 汉寿县| 建平县|