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

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

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

瀏覽:4日期:2023-07-21 18:18:13
運行Consul

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

consul agent --dev

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

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

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

標簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 同德县| 安岳县| 建阳市| 达州市| 二手房| 屏山县| 西乌珠穆沁旗| 成武县| 黄山市| 罗平县| 朔州市| 宁城县| 四川省| 特克斯县| 普宁市| 东宁县| 虎林市| 义马市| 曲周县| 蓬溪县| 禹州市| 开原市| 枞阳县| 新巴尔虎右旗| 元朗区| 汝南县| 云龙县| 旬阳县| 班玛县| 长丰县| 柳林县| 五家渠市| 阜新市| 汤原县| 尤溪县| 乐平市| 商城县| 琼中| 邢台县| 大安市| 呼伦贝尔市|