# SpringCloud 服务无法注册问题


  • 问题描述:服务可以启动,但是注册中心看不到服务的相关注册信息。解决办法如下:在服务的配置文件中详细的配置注册中心的地址等相关信息。

解决办法一

排查有没有引入相关的依赖,注册中心的启动类有没有加@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>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全栈程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值