Spring Cloud Consul的服務(wù)注冊(cè)與發(fā)現(xiàn)
以Windows為例,下載解壓后,以開(kāi)發(fā)模式運(yùn)行:
consul agent --dev
啟動(dòng)成功后,可以訪問(wèn)Consul提供的管理頁(yè)面,默認(rèn)端口為8500,頁(yè)面上顯示了已注冊(cè)服務(wù)的列表,包括它們的運(yùn)行狀況等信息。
<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ù)信息:
使用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)文章!
相關(guān)文章:
1. Springboot 全局日期格式化處理的實(shí)現(xiàn)2. Java GZip 基于內(nèi)存實(shí)現(xiàn)壓縮和解壓的方法3. SpringBoot+TestNG單元測(cè)試的實(shí)現(xiàn)4. 存儲(chǔ)于xml中需要的HTML轉(zhuǎn)義代碼5. 利用CSS制作3D動(dòng)畫(huà)6. Java鏈表元素查找實(shí)現(xiàn)原理實(shí)例解析7. .Net加密神器Eazfuscator.NET?2023.2?最新版使用教程8. Python+unittest+requests 接口自動(dòng)化測(cè)試框架搭建教程9. jsp+servlet簡(jiǎn)單實(shí)現(xiàn)上傳文件功能(保存目錄改進(jìn))10. 一款功能強(qiáng)大的markdown編輯器tui.editor使用示例詳解
