SpringCloud Tutorial 1,Eureka Server;SpringCloud系列教程1,Eureka Server

Spring Cloud是一个基于Springboot项目开发的,它为开发者快速开发分布式系统提供了一系列通用的工具。
Spring Cloud is built on Springboot, and it provides tools for the common patterns in distributed systems.
Eureka Server是Spring Cloud推荐的服务注册中心,本文介绍Eureka Server的搭建。
Eureka Server is the recommended Service Registration. This blog talks about how to build the Eureka Server.
首先,创建一个maven项目,并且设置其对于Spring Cloud的依赖。
First, create a maven project, and set its dependency on Spring Cloud.
其次,新建一个子moudle,设置对于spring-cloud-starter-netflix-eureka-server的依赖。
Second, create a child moudle and set its dependency on spring-cloud-starter-netflix-eureka-server.
第三,创建启动类。
Thirdly, create the start class.
1
2
3
4
5
6
7
8
9
10
11
12
13
package com.gerry.springcloudtest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaServerApplication.class, args);
    }
}
第四,创建并设置application.yml
Fourth, create and set the application.yml
1
2
3
4
5
6
7
8
9
10
11
12
server:
  port: 8761  #the port on which the application runs

eureka:
  instance:
    hostname: 127.0.0.1 #the hostname of the eureka instance
    prefer-ip-address:  true #whether prefer ip address to register on the Eureka Server or not
  client:
    registerWithEureka: false #if it is false, the instance will only host as the Eureka Server, not as the client
    fetchRegistry:  false #whether it will be registered on the Eureka Server
    serviceUrl:
      defaultZone:  http://${eureka.instance.hostname}:${server.port}/eureka/ #the default zone of the Eureka Server
最后,启动项目,浏览器查看http://127.0.0.1:8761/,确认Eureka Server成功启动
Finally, run the application, and open http://127.0.0.1:8761/ in the browser to check whether the Eureka Server starts successfully.
项目已托管在Github,地址https://github.com/tzry/springclouddemo
The project is hosted on Github, the url is https://github.com/tzry/springclouddemo



Leave a Reply

Your email address will not be published. Required fields are marked *