pom.xml 加入依赖
<!-- eureka-client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
在resources中加入application.yml 文件,内容为
server:
port: 8761
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
启动类加上@EnableEurekaServer标注
启动成功后打开http://localhost:8761/,既表示注册中心启动成功
新建一个微服务,注入到8761端口的注册中心中。
启动服务,刷新http://localhost:8761/,9002端口服务成功注册到Eureka注册中心