创建 Spring Cloud 遇到的坑

1、配置文件中:'eureka.client.service-url' 报错

说法一:defaultZone前面加个空格(我有加空格 但是还是报错 不适用在我这里)

eureka:
 client: service-url:   ##注册地址   defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

说法二:将service-url 改成 serviceUrl (亲测可用)

eureka:
 client:
    serviceUrl:
      ##注册地址
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

2、注解加错

  • Eureka Client:负责将这个服务的信息注册到Eureka Server中
  • Eureka Server:注册中心,里面有一个注册表,保存了各个服务所在的机器和端口号
  • Eureka Feign:Spring Cloud核心组件 实现动态代理 详情请查看地址:https://blog.csdn.net/qq_41701956/article/details/83829539
  • Config Service:配置文件的配置中心
  1. Eureka Server的启动项要加@EnableEurekaServer注解
  2. Eureka Client的启动项要加@EnableEurekaClient注解
  3. Eureka Feign的启动项要加@EnableDiscoveryClient 和 @EnableFeignClients(clients = {HiInterface.class})注解;其中HiInterface.class是一个接口类 用来代理调用Client里面的接口
  4. Config Service的启动项要加 @EnableConfigServer 解;

3、pom.xml 文件少加了

1)、工程启动完就挂了 报错:Unregistering application xxx with eureka with status DOWN  原因是:少了下面的依赖  建议加在总的pom.xml中

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
</dependency>
原文链接:https://blog.csdn.net/u012326462/article/details/81051027

2)、整合Feign报错:No Feign Client for loadBalancing defined!  原因是:少了下面的依赖

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        <version>2.2.2.RELEASE</version>
</dependency>
详情可以查看:https://blog.csdn.net/weixin_44901065/article/details/95224863?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

4、如果有做配置中心,那么有以下两种:

git配置:后期补充

本地配置(亲测可用) : https://blog.csdn.net/lixiaxin200319/article/details/81744775

service要加的依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

原文链接:https://blog.csdn.net/lixiaxin200319/article/details/81744775

client要加的依赖:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
原文地址:https://www.cnblogs.com/gjq1126-web/p/12501985.html