搭建一个 Eureka 服务注册中心,提供其它微服务进行服务注册的环境。
<br/>
步骤如下:
**1. 构建服务注册中心模块:assemb-server-eureka7001**
**2. 在当前模块引入 eureka-sever**
```xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
```
**3. 在当前模块中配置 eureka**
```yml
server:
port: 7001
spring:
application:
name: assemb-server-eureka #微服务名称
eureka:
instance:
hostname: www.eureka7001.com #主机名
client:
fetch-registry: false #不向自己注册自己
register-with-eureka: false #不向自己检索自己
service-url:
#供其他微服务注册到当前eureka的地址
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
```
**4. 在当前模块的启动类上标记注解`@EnableEurekaServe`开启 Eureka 服务**
```java
@EnableEurekaServer
@SpringBootApplication
public class Eureka7001Application {
public static void main(String[] args) {
SpringApplication.run(Eureka7001Application.class, args);
}
}
```
**5. 验证服务注册中心是否构建成功**
启动服务中心,访问 http://www.eureka7001.com:7001/ 显示如下页面则构建成功。
![](https://img.kancloud.cn/0c/26/0c2687d6cea61215ac9a67dc546ad8b2_2226x1288.png)