首先检查有没有导入eureka的启动器,eureka服务端导入的是一定是spring-cloud-starter-netflix-eureka-server,注意不要写成spring-cloud-starter-netflix-eureka-client
eureka:
client:
register-with-eureka:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
如果启动器没问题,接查看eureka的application.yml,特别要注意的是.myl对齐方式,以及指定的注册中心 eureka.client.service-url.defaultZone的地址是否正确,端口号是否对应,有没有被占用。
server:
port: 10001
spring:
application:
name: leyou-registry
eureka:
client:
service-url:
defaultZone: http://localhost:${server.port}/eureka
fetch-registry: true
register-with-eureka: true
这里eureka.client.register-with-eureka:的意思是向不向eureka的注册中心注册自己,默认为true(注册自己),false即为不注册自己,一般情况下是不注册自己。但是这里填true也无关紧要编译器会报一次错,但是eureka服务器依然可以打开。
eureka:
client:
register-with-eureka: false
fetchRegistry: false