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. SpringMVC+Jquery實(shí)現(xiàn)Ajax功能2. 解析原生JS getComputedStyle3. ASP 連接Access數(shù)據(jù)庫(kù)的登陸系統(tǒng)4. Jsp中request的3個(gè)基礎(chǔ)實(shí)踐5. 詳解瀏覽器的緩存機(jī)制6. jsp EL表達(dá)式詳解7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫(kù)的方法8. IE6/IE7/IE8/IE9中tbody的innerHTML不能賦值的完美解決方案9. 詳解CSS偽元素的妙用單標(biāo)簽之美10. 詳解JSP 內(nèi)置對(duì)象request常見(jiàn)用法
