javascript
《SpringCloud超级入门》使用Eureka编写注册中心服务《九》
首先創(chuàng)建一個(gè) Maven項(xiàng)目,取名為 eureka-server,在 pom.xml 中配置 Eureka 的依賴信息,代碼如下所示。
<!-- Spring Boot --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> <relativePath /> </parent><dependencies> <!-- eureka --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> </dependencies><!-- Spring Cloud --> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.SR2</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>創(chuàng)建一個(gè)啟動(dòng)類 EurekaServerApplication,代碼如下所示。
@EnableEurekaServer @SpringBootApplication public static void main(String[] args) { SpringApplication.run(EurekaServer Application.class, args); } }這里所說的啟動(dòng)類,跟我們之前講的 Spring Boot 幾乎完全一樣,只是多了一個(gè) @EnableEurekaServer 注解,表示開啟 Eureka Server。
接下來在 src/main/resources 下面創(chuàng)建一個(gè) application.properties 屬性文件,增加下面的配置:
eureka.client.register-with-eureka 一定要配置為 false,不然啟動(dòng)時(shí)會(huì)把自己當(dāng)作客戶端向自己注冊(cè),會(huì)報(bào)錯(cuò)。
接下來直接運(yùn)行 EurekaServerApplication 就可以啟動(dòng)我們的注冊(cè)中心服務(wù)了。我們?cè)?application.properties 配置的端口是 8761,則可以直接通過 http://localhost:8761/ (http://localhost%EF%BC%9A8761/) 去瀏覽器中訪問,然后便會(huì)看到 Eureka 提供的 Web 控制臺(tái)。
上一篇 Spring Cloud Eureka是什么?
下一篇介紹 使用Eureka編寫服務(wù)提供者
總結(jié)
以上是生活随笔為你收集整理的《SpringCloud超级入门》使用Eureka编写注册中心服务《九》的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: npm install packagen
- 下一篇: HTML+CSS+JS实现 ❤️九宫格图