• endpoint=DefaultEndpoint{ serviceUrl=‘http://127.0.0.1:10086/eureka/


    废话

    跟着B站黑马课程进行学习的,如果是完全按照课程的代码打下来,我这里会出manymany多的bug…

    bug与网上的解决方案

    endpoint=DefaultEndpoint{ serviceUrl='http://127.0.0.1:10086/eureka/‘
    
    • 1

    首先就是启动eureka-service时候报的经典错,网上好多说拼写的问题,这里我仔细检查了一遍也没有问题。
    又看到说再配置文件中加上

    register-with-eureka: false
    fetch-registry: false
    
    • 1
    • 2

    就不会报错了,但我心想,课程里面是也要把eureka服务注册到自己中,这样都设置成false不就有种顾头不顾腚的感觉了。
    还有的说先把端口换成8761启动,然后再换回去
    改域名,name之类等等

    解决方法

    最终是在项目Pom.xml配置文件中发现
    在这里插入图片描述
    一开始写的是pom,改了之后就OK了

    其他问题

    重新启动后打开
    在这里插入图片描述
    这里显示的这个ip地址是我虚拟网卡的ipv4
    在这里插入图片描述
    所以我们手动更改

    在这里插入图片描述
    就像上图,就算添加了也只是改的
    在这里插入图片描述这个地方,上面的未被更改,

    在这里插入图片描述
    关于eureka自己添加自己
    eureka在启动的过程中,先会去eureka注册中心检索服务,由于自身正在启动过程中,所以会连接失败,因此会报错。所以当加上这个参数:fetch-registry: false 就不会报错了。
    但是register-with-eureka一定要设置为true呀要不就没意义了
    在这里插入图片描述

    这里附上yml源码(依赖和注解不做展示)

    eureka-service

    server:
      port: 8762
    spring:
      application:
        name: eureka-service
    
    eureka:
      client:
        service-url:
          defaultZone: http://127.0.0.1:8762/eureka
        register-with-eureka: true
        fetch-registry: false
      instance:
        prefer-ip-address: true
        ip-address: 127.0.0.1
        instance-id: localhost:${spring.application.name}:${server.port}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    order-service

    server:
      port: 8082
    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/cloud_order?useSSL=false
        username: root
        password: root
        driver-class-name: com.mysql.jdbc.Driver
      application:
        name: order-service
    mybatis:
      type-aliases-package: cn.itcast.user.pojo
      configuration:
        map-underscore-to-camel-case: true
    logging:
      level:
        cn.itcast: debug
      pattern:
        dateformat: MM-dd HH:mm:ss:SSS
    eureka:
      client:
        service-url:
          defaultZone: http://127.0.0.1:8762/eureka
      instance:
        prefer-ip-address: true # 当其它服务获取地址时提供ip而不是hostname
        ip-address: 127.0.0.1 # 指定自己的ip信息,不指定的话会自己寻找
        instance-id: localhost:${spring.application.name}:${server.port}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    user-service

    server:
      port: 8081
    spring:
      datasource:
        url: jdbc:mysql://localhost:3306/cloud_user?useSSL=false
        username: root
        password: root
        driver-class-name: com.mysql.jdbc.Driver
      application:
        name: user-service
    
    mybatis:
      type-aliases-package: cn.itcast.user.pojo
      configuration:
        map-underscore-to-camel-case: true
    logging:
      level:
        cn.itcast: debug
      pattern:
        dateformat: MM-dd HH:mm:ss:SSS
    
    eureka:
      client:
        service-url:
          defaultZone: http://127.0.0.1:8762/eureka
      instance:
        prefer-ip-address: true # 当其它服务获取地址时提供ip而不是hostname
        ip-address: 127.0.0.1 # 指定自己的ip信息,不指定的话会自己寻找
        instance-id: localhost:${spring.application.name}:${server.port}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    欢迎交流讨论!

  • 相关阅读:
    Linux常用命令
    机器学习分类
    安全认证 | CISP考试资格及报考条件
    调查:三分之一接受调查的黄金买家认为比特币是更好的选择
    天天提交代码,git commit 提交时能规范一下吗?
    分布式全局唯一ID生成方案(附源码)
    【每日一题】切割后面积最大的蛋糕
    服务接口调用OpenFeign_超时机制
    activiti7的数据表和字段的解释
    【pytest】html报告修改和汉化
  • 原文地址:https://blog.csdn.net/kanbujianwolue/article/details/126070376