標籤: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構建微服務架構—建立“服務註冊中心”