Spring Cloud構建微服務架構—建立“服務註冊中心”

來源:互聯網
上載者:User

標籤:water   builder   http   .class   process   簡單   type   false   frame   

建立一個基礎的Spring Boot工程,命名為eureka-server,並在pom.xml中引入需要的依賴內容:

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.4.RELEASE</version><relativePath/></parent><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Dalston.SR1</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>

通過@EnableEurekaServer註解啟動一個服務註冊中心提供給其他應用進行對話。這一步非常的簡單,只需要在一個普通的Spring Boot應用中添加這個註解就能開啟此功能,比如下面的例子:

@EnableEurekaServer@SpringBootApplicationpublic class Application {public static void main(String[] args) {new SpringApplicationBuilder(Application.class).web(true).run(args);}}

在預設設定下,該服務註冊中心也會將自己作為用戶端來嘗試註冊它自己,所以我們需要禁用它的用戶端註冊行為,只需要在application.properties設定檔中增加如下資訊:

spring.application.name=eureka-serverserver.port=1001eureka.instance.hostname=localhosteureka.client.register-with-eureka=falseeureka.client.fetch-registry=false

為了與後續要進行註冊的服務區分,這裡將服務註冊中心的連接埠通過server.port屬性設定為1001。啟動工程後,可以看到下面的頁面,其中還沒有發現任何服務。

從現在開始,我這邊會將近期研發的springcloud微服務雲架構的搭建過程和精髓記錄下來,協助更多有興趣研發spring cloud架構的朋友,希望可以協助更多的好學者。大家來一起探討spring cloud架構的搭建過程及如何運用於企業專案。

Spring Cloud構建微服務架構—建立“服務註冊中心”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.