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

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.mrgr.cn/news/51380.html

相关文章:

  • 基于 Konva 实现Web PPT 编辑器(三)
  • 博科测试IPO上市丨为行业提供智能测试综合解决方案
  • 建筑八大员标准员试题附答案
  • 从一个事故中理解 Redis(几乎)所有知识点
  • CAS相关知识
  • simpleITK和itk获取mask图像轮廓
  • 实战篇:(十一)JavaScript 网页设计案例:使用 Canvas 实现趣味打气球小游戏
  • 深度解析 Redis 存储结构及其高效性背后的机制
  • ESB服务集成是什么?如何运作的?有什么优势?
  • 大健康创新企业:私域流量与绿色积分共铸销售飞跃
  • SpringMVC源码-接口请求执行流程,包含九大内置组件的实例化初始化,拦截器调用,页面渲染等源码讲解
  • JavaSE——集合9:Map接口实现类—HashMap(重要!!!)
  • 快速创建品牌百度百科词条
  • 三类非常重要的约定管辖的法律效力
  • 9月份最新海关数据公布,增长6.2%
  • 2024双十一养猫清单给你们整理出来了高性价比盲抄作业不踩雷
  • 绕过MIME-Type验证
  • yolo笔记
  • 【C++】—通俗易懂的理解C++中的模板
  • 猫鼠游戏: KaijiK病毒入侵溯源分析