您好,登錄后才能下訂單哦!
這篇文章給大家介紹怎樣進(jìn)行搭建Eureka注冊(cè)中心,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
一 創(chuàng)建一個(gè)Spring Boot工程,命名為eureka-server,并在pom.xml中引入必要的依賴。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.7.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-actuator</artifactId>--> <!--</dependency>--> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.SR5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
二 通過@EnableEurekaServer注解啟動(dòng)一個(gè)服務(wù)注冊(cè)中心提供給其他應(yīng)用程序進(jìn)行對(duì)話,只需要在Spring Boot應(yīng)用中添加下面這個(gè)注解就能開啟此功能。
@EnableEurekaServer @SpringBootApplication public class Application { public static void main(String[] args) { new SpringApplicationBuilder(Application.class).web(true).run(args); } }
三 在默認(rèn)情況下,服務(wù)注冊(cè)中也會(huì)將自己作為客戶端來嘗試注冊(cè)它自己,所以需要禁用它的客戶端行為。
application.properties中增加如下配置。 spring.application.name=eureka-server server.port=1111 eureka.instance.hostname=localhost # 關(guān)閉保護(hù)機(jī)制 #eureka.server.enable-self-preservation=false eureka.client.register-with-eureka=false eureka.client.fetch-registry=false eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/ logging.file=${spring.application.name}.log
說明:
eureka.client.register-with-eureka:由于該應(yīng)用為注冊(cè)中心,所以設(shè)置為false,代表不向注冊(cè)中心注冊(cè)自己。
eureka.client.fetch-registry:由于注冊(cè)中心的職責(zé)就是維護(hù)服務(wù)實(shí)例,它并不需要去檢索服務(wù),所以也設(shè)置為false。
關(guān)于怎樣進(jìn)行搭建Eureka注冊(cè)中心就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。