一、系统学习微服务遇到的问题集合

1、启动了nacos服务,没有在注册列表

应该是版本问题

Alibaba-nacos版本
nacos-文档
Spring Cloud Alibaba-中文
Spring-Cloud-Alibaba-英文

Spring-Cloud-Gateway

写的很好的一篇文章

在Spring initial上面配置

start.aliyun.com

重新下载
<

2、 No Feign Client for loadBalancing defined.

No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

由于使用了 OpenFeigin, 引入依赖

<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> <version>3.0.1</version> </dependency>

3、NoClassDefFoundError org/springframework/boot/Bootstrapper

3.1 Spring Boot 依赖版本与 Spring Cloud Alibaba依赖版本不一致

根据版本表,配置springCloud,SpringBoot,CloudAlibaba

3.2 接着再启动报错:

The dependencies of some of the beans in the application context form a cycle:

| restTemplateController (field public org.springframework.web.client.RestTemplate com.example.cloud.demos.nacosdiscoveryconsumer.RestTemplateController.restTemplate)

在这个controller中,循环注入。

把这个移到其他类中。

3.3 Caused by: com.alibaba.nacos.api.exception.NacosException: Client not connected, current status:STARTING

链接不上nacos服务器。这里有两个方面:

  • nacos服务端 2.0.x版本要开放 8848端口
  • nacos服务端为2.1.2 ,客户端降低版本至 1.4.1就OK了
<dependency> <groupId>com.alibaba.nacos</groupId> <artifactId>nacos-client</artifactId> <version>1.4.1</version> </dependency>

现在在服务列表上就能看见注册信息了。

4、Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway.

Spring Cloud Gateway的项目中不能用 SpringMVC的依赖

在依赖中排除

<exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-start-web</artifactId> </exclusion> </exclusions>

5、Caused by: java.net.UnknownHostException: nacos-service

这个要加入依赖

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency>

5.1 You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.

启动带了@Loadbalanced 注解,就有这个提示。

  • 引入caffeine依赖
<dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> <version>2.9.3</version> </dependency>

引入了依赖,还有这个提示日志

根据这个提示,找到了这个类 LoadBalancerCacheAutoConfiguration

static final class OnCaffeineCacheMissingCondition extends AnyNestedCondition { private OnCaffeineCacheMissingCondition() { super(ConfigurationPhase.REGISTER_BEAN); } @ConditionalOnMissingClass("com.github.benmanes.caffeine.cache.Caffeine") static class CaffeineClassMissing { } @ConditionalOnMissingClass("org.springframework.cache.caffeine.CaffeineCacheManager") static class CaffeineCacheManagerClassMissing { } }

根据这个丢失条件,Caffeine 这个类是caffeine依赖。而 CaffeineCacheManager 则是在 spring-context-support 中,也引入次依赖

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency>

成功,没有警告日志,且异服务之间调用成功,用的 consumer-service 调用 nacos-service

6、一直提示 "error": "Service Unavailable"

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>com.github.ben-manes.caffeine</groupId> <artifactId>caffeine</artifactId> <version>2.9.3</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-loadbalancer</artifactId> </dependency>

问题解决

这是由于版本不兼容引发的问题,我当前使用的版本

  • alibaba-nacos-discovery 2021.0.5.0

而springcloud alibaba 在2020版之后不支持ribbon,可以使用 loadbalance 代替。

7、请求路径一直报“Not fund”

对 Path路由理解错误

routes: - id: nacos-service_route uri: lb://nacos-service predicates: - Path=/api/**

这个请求地址为:localhost:8081/api/echo/xxx

这个其实是生效了的,gateway已经转发到了 nacos-service服务。

只是对于路径 nacos-service/api/echo/xxx 没有找到,它替换的只是注册的服务而已,具体的路径并没有替换。


__EOF__

本文作者山沉
本文链接https://www.cnblogs.com/Choleen/p/18264055.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   山沉  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示