1、前提
springcloud的注册中心是以springboot为基础搭建起来的。
开发工具:IDEA
项目管理工具:maven
2、搭建步骤
- 创建一个web项目(建议使用IDEA工具构建项目)
- 修改pom文件
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.4.4.RELEASE</version>
</dependency> - 在springboot的启动类上加上@EnableEurekaServer注解
- 添加配置文件
#项目名
spring.application.name=spring-cloud-eureka
#端口号
server.port=8000
#表示是否将自己注册到Eureka Server,默认为true
eureka.client.register-with-eureka=false
#表示是否从Eureka Server获取注册信息,默认为true。
eureka.client.fetch-registry=false
#设置与Eureka Server交互的地址,查询服务和注册服务都需要依赖这个地址。默认是http://localhost:8761/eureka ;多个地址可使用 , 分隔。
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/
3、效果