當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
《SpringCloud超级入门》使用Eureka编写注册中心服务《九》
生活随笔
收集整理的這篇文章主要介紹了
《SpringCloud超级入门》使用Eureka编写注册中心服务《九》
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
首先創建一個 Maven項目,取名為 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>創建一個啟動類 EurekaServerApplication,代碼如下所示。
@EnableEurekaServer @SpringBootApplication public static void main(String[] args) { SpringApplication.run(EurekaServer Application.class, args); } }這里所說的啟動類,跟我們之前講的 Spring Boot 幾乎完全一樣,只是多了一個 @EnableEurekaServer 注解,表示開啟 Eureka Server。
接下來在 src/main/resources 下面創建一個 application.properties 屬性文件,增加下面的配置:
eureka.client.register-with-eureka 一定要配置為 false,不然啟動時會把自己當作客戶端向自己注冊,會報錯。
接下來直接運行 EurekaServerApplication 就可以啟動我們的注冊中心服務了。我們在 application.properties 配置的端口是 8761,則可以直接通過 http://localhost:8761/ (http://localhost%EF%BC%9A8761/) 去瀏覽器中訪問,然后便會看到 Eureka 提供的 Web 控制臺。
上一篇 Spring Cloud Eureka是什么?
下一篇介紹 使用Eureka編寫服務提供者
總結
以上是生活随笔為你收集整理的《SpringCloud超级入门》使用Eureka编写注册中心服务《九》的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: npm install packagen
- 下一篇: gradle idea java ssm