SpringCloudAlibaba升级手册

embedded/2024/10/20 13:03:19/

目录

1. 版本对照

版本现状

SpringCloud%E4%B8%8EAlibabaCloud%E5%AF%B9%E5%BA%94%E7%89%88%E6%9C%AC-toc" style="margin-left:80px;">SpringCloud与AlibabaCloud对应版本

Springboot与Elasticsearch版本对应

2. openfeign问题

问题

解决方案

3. Feign请求问题

问题

解决方法

4. Sentinel循环依赖

问题

解决方案

5. bootstrap配置文件不生效

问题

解决方案

6. Nacos的连接错误

问题

解决方案

7. 跨域问题

问题

解决方案


1. 版本对照

版本现状

组件

版本

新版本

SpringBoot

2.3.2.RELEASE

2.7.18

SpringCloud

Hoxton.SR9

2021.0.9

SpringCloudAlibaba

2.2.6.RELEASE

2021.0.5.0

spring-boot-starter-data-elasticsearch

2.3.2.RELEASE

SpringBoot版本内部定义

nacos-client

1.4.2

AlibabaCloud版本内部定义(2.2.0)

SpringCloud%E4%B8%8EAlibabaCloud%E5%AF%B9%E5%BA%94%E7%89%88%E6%9C%AC" style="text-align:justify;">SpringCloud与AlibabaCloud对应版本

信息来源:

版本发布说明-阿里云Spring Cloud Alibaba官网

Springboot与Elasticsearch版本对应

Spring Boot 和 Elasticsearch 的版本兼容关系需要根据 Spring Data Elasticsearch 模块的版本来确定,因为 Spring Boot 通过 Spring Data Elasticsearch 来集成 Elasticsearch。以下是一些常见的版本对应关系

Spring Boot 版本

Spring Data Elasticsearch 版本

Elasticsearch 版本

3.1.x

5.1.x

8.x

3.0.x

5.0.x

8.x

2.7.x

4.4.x

7.x

2.6.x

4.3.x

7.x

2.5.x

4.2.x

7.x

2.4.x

4.1.x

7.x

2.3.x

4.0.x

7.x

2.2.x

3.2.x

6.x

2.1.x

3.1.x

6.x

2.0.x

3.0.x

5.x

    RestHighLevelClient:从 Spring Data Elasticsearch 4.x 开始,推荐使用 Elasticsearch 官方的 RestHighLevelClient 代替旧的 TransportClient。

    Elasticsearch 7.x 引入了一些重要的映射变化,比如默认情况下不再需要指定 _type 字段,所有文档类型默认使用 _doc。

2. openfeign问题

问题

Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: @RequestMapping annotation not allowed on @FeignClient interfaces

Spring Cloud OpenFeign 3.x 版本中 @FeignClient 接口上不允许使用 @RequestMapping 注解的限制。

解决方案

将老代码中的 @RequestMapping 替换为具体的请求方式注解,例如 @GetMapping、@PostMapping 等。

修改前:

@FeignClient(name = "example-service")@RequestMapping("/example")public interface ExampleFeignClient {@RequestMapping(method = RequestMethod.GET, value = "/getData")String getData();}

修改后:

@FeignClient(name = "example-service")public interface ExampleFeignClient {@GetMapping("/example/getData")String getData();}

Content-Type 头部设置了一个不允许的通配符 '*',而 Feign 不支持这种情况。

注解中加上 consumes = "application/json"参数,明确规定了请求的 Content-Type。

3. Feign请求问题

问题

Unexpected exception during bean creation; nested exception is java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalancer?

解决方法

你可以通过在 pom.xml 文件中手动添加 spring-cloud-starter-loadbalancer 依赖来解决这个问题:

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

4. Sentinel循环依赖

问题

Description:

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

   xxxxxImpl

      ↓

   XxxxxImpl

      ↓

   org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration

┌─────┐

|  com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration (field private java.util.Optional com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration.sentinelWebInterceptorOptional)

└─────┘

Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

解决方案

升级为当前 Spring Cloud 一样的版本。

<!--sentinel版本-->
<spring-cloud-starter-alibaba-sentinel.version>2021.0.5.0</spring-cloud-starter-alibaba-sentinel.version>

参考资料:

https://github.com/alibaba/spring-cloud-alibaba/issues/2322
https://juejin.cn/post/7080801716483915783  alibaba-sentinel启动报循环依赖
https://developer.aliyun.com/article/861163  springboot升级到2.6.1的坑
https://cloud.tencent.com/developer/article/2186649  我服了!SpringBoot升级后这服务我一个星期都没跑起来!

5. bootstrap配置文件不生效

问题

org.springframework.cloud.commons.ConfigDataMissingEnvironmentPostProcessor$ImportException: No spring.config.import set

Description:

No spring.config.import property has been defined

Action:

Add a spring.config.import=nacos: property to your configuration.

If configuration is not required add spring.config.import=optional:nacos: instead.

To disable this check, set spring.cloud.nacos.config.import-check.enabled=false.

解决方案

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

参考资料:

https://cloud.tencent.com/developer/ask/sof/108770896
https://sca.aliyun.com/en/faq/sca-user-question-history13954/

6. Nacos的连接错误

问题

ErrCode:-401, ErrMsg:Client not connected,current status:STARTING的解决方案

解决方案

开通相应新增端口

参考资料:

https://www.cnblogs.com/linyb-geek/p/16601335.html
https://nacos.io/zh-cn/docs/v2/upgrading/2.0.0-compatibility.html
https://blog.csdn.net/fenglibing/article/details/120164149

7. 跨域问题

问题

java.lang.IllegalArgumentException: When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.

解决方案

SpringBoot升级2.4.0之后,跨域配置中的.allowedOrigins不再可用,将配置中的.allowedOrigins替换成.allowedOriginPatterns即可

参考资料:

https://blog.csdn.net/weixin_43901865/article/details/119737447


http://www.ppmy.cn/embedded/128998.html

相关文章

软考(网工)——网络安全

文章目录 &#x1f550;网络安全基础1️⃣网络安全威胁类型2️⃣网络攻击类型 &#x1f551;现代加密技术1️⃣私钥密码/对称密码体制2️⃣对称加密算法总结3️⃣公钥密码/非对称密码4️⃣混合密码5️⃣国产加密算法 - SM 系列6️⃣认证7️⃣基于公钥的认证 &#x1f552;Hash …

AcWing1027

题目重述&#xff1a; 题目的核心是找到一条路径的最大权值总和&#xff0c;但路径要从起点 (1, 1) 走到终点 (n, n)。由于两条路径分别经过不同的格子&#xff0c;我们可以巧妙地将问题简化为两次同时出发的路径问题。这种映射的设计让我们能够更方便地处理两条路径重叠在同一…

探索 Python Web 开发:从框架到爬虫

Python 是 Web 开发中广泛使用的编程语言&#xff0c;因其简单、灵活和强大的生态系统&#xff0c;适合构建各种类型的 Web 应用和 API。在本篇博客中&#xff0c;我们将讨论 Web 开发的几个重要主题&#xff0c;包括 Flask 和 Django 框架、API 开发、HTTP 请求处理以及网页爬…

Qt贪吃蛇-游戏逻辑设计(4)

目录 游戏房间 实现游戏开始和游戏暂停 设置移动按钮 退出游戏 绘制分数 绘制游戏失败效果 控制蛇的移动速度 添加吃食物的音效 选择大厅 历史记录绑定信号槽 往文件中写入分数 承接上文 游戏房间 实现游戏开始和游戏暂停 setLoops 参数是循环的次数&#xff0c…

如何快速学会盲打

今天就来给大家分享一下如何快速学会盲打 盲打的基本方法和步骤 手指放置&#xff1a;将双手放在键盘上&#xff0c;左手食指放在F键上&#xff0c;右手食指放在J键上&#xff0c;其他手指分别放在相邻的键位上。熟悉键盘布局&#xff1a;学习26个字母的位置&#xff0c;以及…

Docker报错-Docker Desktop - Unexpected WSL error

使用超级管理员Shell键入命令 netsh winsock reset 重启后即可。

Qt 每日面试题 -9

81、请写一个调用消息对话框提示报错的程序 QMessageBox::waring(this,tr("警告"), tr("用户名或密码错误!"),QMessageBox::Yes)82、Qt都提供哪些标准对话框以供使用&#xff0c;他们实现什么功能? Qt提供9个标准对话框: QColorDialog 颜色对话框&…

C++20中头文件span的使用

<span>是C20中新增加的头文件&#xff0c;此头文件是containers库的一部分。包括&#xff1a; 1.模板类std::span&#xff1a;连续对象序列的非拥有视图(view)。std::span可以具有static extent&#xff0c;在这种情况下&#xff0c;序列中的元素数量在编译时已知并以typ…