- 问题描述:服务可以启动,但是注册中心看不到服务的相关注册信息。解决办法如下:在服务的配置文件中详细的配置注册中心的地址等相关信息。
解决办法一
排查有没有引入相关的依赖,注册中心的启动类有没有加@EnableEurekaServer
注解。服务模块中有没有加入eureka的客户端依赖,如果没有添加那么添加相关的依赖,依赖如下:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
解决办法二
例如注册中心的配置如下:注册中心的端口为8001
# 端口号
server:
port: 8001
spring:
application:
name: eurekaserver
eureka:
instance:
hostname: localhost # Eureka访问地址
client:
register-with-eureka: false # 禁止自己注册自己
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
当服务注册不了的时候在服务的配置文件中添加详细的注册中心的信息如下:menu-dev.xml
server:
port: 8011
spring:
application:
name: menu
datasource:
url: jdbc:mysql://localhost:3306/shop?useUnicode=true
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
instance:
prefer-ip-address: true
当再次查看注册中心时候可以看到已经注册的服务。
解决办法三
微服务模块注册时报错:Shutting down DiscoveryClient
- 解决办法:加上
Spring boot web
的依赖包,修改依赖如下
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>