当前位置: 首页 > article >正文

SpringCloudAlibaba升级手册

目录

1. 版本对照

版本现状

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与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.kler.cn/news/350628.html

相关文章:

  • ubuntu GLEW could not be initialized : Unknown error
  • 什么是域名?什么是泛域名?
  • HivisionIDPhoto Docker部署以及Springboot接口对接(AI证件照制作)
  • 蓝牙技术的多种模式详解
  • ESlint代码规范
  • SAP_SD模块-销售订单创建价格扩大10倍问题分析及后续订单价格批量更新问题处理
  • Finops成本优化企业实践-可规划篇
  • linux线程 | 线程的控制(下)
  • linux下在线安装MySQL-华为云服务器
  • 【WebLogic】Oracle发布2024年第四季度中间件安全公告
  • Sharding-JDBC标准模式详解
  • Java基础:面向对象编程5
  • 恢复已删除文件的 10 种安卓数据恢复工具
  • IRP默认最小流程
  • 2023年“网络建设与运维”广西省赛试题复盘
  • yakit使用教程(四,信息收集)
  • WorkFlow GO-Task 源码分析
  • 简单说说mysql中一条读sql是如何执行的
  • 2023年12月中国电子学会青少年软件编程(Python)等级考试试卷(一级)答案 + 解析
  • PowerShell中conda activate指令无效的问题
  • CentOS硬解码+ffmpeg+Nvidia硬解码
  • 探索人工智能在数学教育上的应用——使用大规模语言模型解决数学问题的潜力和挑战
  • 学习 Python 的途径
  • 基于深度学习的车辆车型检测识别系统(YOLOV5)
  • 太速科技-456-FMCJ456-14bit 2通道3/2.6/2GS/s ADC +16bit 2通道12.6GS/s DAC FMC AD/DA子卡
  • WSL2配置代理解决git网络不通畅的问题