搭建Eureka Server(基于Springboot项目中搭建)
-
因为是基于Springboot项目中搭建,先创建springboot项目
-
创建springboot…省略
-
创建完成后在pom.xml中添加Eureka相关坐标
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency>
-
添加导入Spring Cloud的依赖管理
<dependencyManagement> <dependencies> <!-- 导入Spring Cloud的依赖管理 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
-
在在.yml配置文件中配置(也可以在properties中)
###服务端口号 server: port: 8080 ###服务名称 spring: application: name: app-eureka-center eureka: instance: #注册中心地址 hostname: 127.0.0.1 ###客户端调用地址 client: serviceUrl: defaultZone: http://${eureka.instance.hostname}:8080/eureka/ ###是否将自己注册到Eureka服务中,因为该应用本身就是注册中心,不需要再注册自己(集群的时候为true) register-with-eureka: false ###是否从Eureka中获取注册信息,因为自己为注册中心,不会在该应用中的检索服务信息 fetch-registry: false
-
在Springboot启动类上添加 @EnableEurekaServer 证明这是一个Eureka服务
-
启动springboot,并在浏览器访问http://localhost:8080/,出现下面界面注册中心就搭建完成了.