spring cloud 2021.0.1升级踩坑记录

2023-10-31

一、版本说明

升级前的版本:

spring boot 2.2.2.RELEASE
spring cloud Hoxton.SR1
spring cloud alibaba 2.2.0.RELEASE

升级后版本:

spring boot 2.6.10
spring cloud 2021.0.1
spring cloud alibaba 2021.0.1.0 

二、属性扫描

升级到新功能版本时,某些属性可能已重命名或删除。Spring Boot 提供了一种在启动时分析应用程序环境和打印诊断信息的方法,还可以在运行时为您临时迁移属性。要启用该功能,请将以下依赖项添加到您的项目中: 

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-properties-migrator</artifactId>
    <scope>runtime</scope>
</dependency>

增加依赖之后运行项目,控制台会输出变更的属性信息: 

2022-08-09 20:00:40.133|my-test||ERROR|main|org.springframework.boot.context.properties.migrator.PropertiesMigrationListener|100|
The use of configuration keys that are no longer supported was found in the environment:

Property source 'bootstrapProperties-my-test-common.yaml,IMS_GROUP':
	Key: spring.flyway.ignore-missing-migrations
		Reason: Replacement key 'spring.flyway.ignore-migration-patterns' uses an incompatible target type


Please refer to the release notes or reference guide for potential alternatives.

2022-08-09 20:00:40.146|my-test||INFO|main|org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener|136|

 注意:

完成迁移后,请确保从项目的依赖项中删除此模块。

三、 升级的问题

问题1 :Hystrix依赖包找不到

原因: 移除了对Hystrix的支持.(集成alibaba的sentinel作为替代方案

 问题2:No Feign Client for loadBalancing defined.

 解决:原因是移除了对Ribbon的支持,需切换成 loadbalancer 实现

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

问题3:循环依赖 Relying upon circular references is discouraged and they are prohibited by default.

解决:两种方法

方法一:在配置文件增加如下配置项

spring:
   main:
     allow-circular-references: true



方法二:修改pagehelper版本为1.4.1

    <dependencies>
        <!--MyBatis分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.1</version><!--必须是这个版本,其他版本有相互依赖的类,例如A类依赖B类,B类又引用了A类 -->
        </dependency>
    </dependencies>

问题4:java.lang.IllegalArgumentException: Param 'serviceName' is illegal, serviceName is blank 

 解决:原因是使用了bootstrap.yml配置文件,而springcloud2.4版本之后不支持加载bootstrap.yml文件,需增加以下依赖。并且在bootstrap.yml里面增加配置spring.cloud.nacos.discovery.service=xxx

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>
spring:
  cloud:
    nacos:
      discovery:
        service: testgrpc

问题5:日志输出applicationName_IS_UNDEFINED

解决:原因是logback-spring.xml文件中的配置读不到值

<springProperty scope="context" name="applicationName" source="spring.application.name"/>

 在配置文件增加配置spring.cloud.nacos.discovery.service=xxx

spring:
  application:
    name: mytest
  cloud:
    nacos:
      discovery:
        server-addr: ${NACOS_ADDR:127.0.0.1}:${NACOS_PORT:8848}
        namespace: ${NACOS_NAMESPACE:test}
        group: ${NACOS_GROUP:TEST_GROUP}
        service: ${spring.application.name}

问题6:Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
	at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
	at com.zhdgps.ims.GnssApplication.main(GnssApplication.java:32)
Caused by: java.lang.NullPointerException: null
	at springfox.documentation.spi.service.contexts.Orderings$8.compare(Orderings.java:112)
	at springfox.documentation.spi.service.contexts.Orderings$8.compare(Orderings.java:109)
	at com.google.common.collect.ComparatorOrdering.compare(ComparatorOrdering.java:37)
	at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
	at java.base/java.util.TimSort.sort(TimSort.java:220)
	at java.base/java.util.Arrays.sort(Arrays.java:1441)
	at com.google.common.collect.Ordering.sortedCopy(Ordering.java:855)
	at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:57)
	at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:138)
	at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:135)
	at com.google.common.collect.Iterators$7.transform(Iterators.java:750)
	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47)
	at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47)
	at com.google.common.collect.MultitransformedIterator.hasNext(MultitransformedIterator.java:52)
	at com.google.common.collect.MultitransformedIterator.hasNext(MultitransformedIterator.java:50)
	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:249)
	at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:209)
	at com.google.common.collect.FluentIterable.toList(FluentIterable.java:614)
	at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.defaultContextBuilder(DocumentationPluginsBootstrapper.java:111)
	at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.buildContext(DocumentationPluginsBootstrapper.java:96)
	at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:167)
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
	... 14 common frames omitted

 解决:原因是 对swagger2不兼容,需要升级为swagger3

第一步:升级Swagger 版本到3.0

    <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
    </dependency>

我们项目用的是swagger-spring-boot-starter,升级到2.0.2.RELEASE,其内部依赖了swagger3

        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>

第二步:因为Springfox 使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher ,需增加配置如下:

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

第三步: 增加swagger配置

@EnableOpenApi
@Configuration
public class SpringFoxSwaggerConfig {

    /**
     * 增加如下配置可解决Spring Boot 6.x 与Swagger 3.0.0 不兼容问题
     **/
    @Bean
    public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
        List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
        Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
        allEndpoints.addAll(webEndpoints);
        allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
        allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
        String basePath = webEndpointProperties.getBasePath();
        EndpointMapping endpointMapping = new EndpointMapping(basePath);
        boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
        return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
    }
    private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
        return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
    }
}

注意地址后缀变化:

swagger2的访问地址:http://127.0.0.1:8080/gnss/swagger-ui.html 

swagger3的访问地址:http://127.0.0.1:8080/gnss/swagger-ui/index.html

问题7:找不到ResourceProperties类

  解决:ResourceProperties类已经被移除,用WebProperties替换,可以去WebProperties.Resources静态内部类找

 问题8:Failed to bind properties under 'spring.mail.properties'

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'spring.mail.properties' to java.util.Map<java.lang.String, java.lang.String>:

    Property: spring.mail.properties
    Value: ""
    Origin: "spring.mail.properties" from property source "bootstrapProperties-my-test-notify-service.yaml,IMS_GROUP"
    Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]

Action:

Update your application's configuration

原因:SpringBoot: 2.6.10 对spring某些加载规则更严格,需要适配。配置spring.mail.properties没有赋值,导致转换异常。配置如下:

spring: 
  mail:
    protocol: smtp
    host: smtp.exmail.qq.com
    port: 25
    username: root
    password: 123456
    default-encoding: utf-8
    properties:
    debug: true

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

spring cloud 2021.0.1升级踩坑记录 的相关文章

  • 如何在线程和小程序中使用双缓冲

    我有一个关于何时调用绘制和更新方法的问题 我有游戏小程序 我想在其中使用双缓冲 但我无法使用它 问题是 在我的游戏中 有一个球在 run 方法内移动 我想知道如何使用双缓冲来交换屏幕外图像和当前图像 请有人帮忙 当同时存在 update 和
  • 将 hyperjaxb3 升级到 jpa 2.1

    我正在尝试在使用 maven jpa hibernate 和 hyperjaxb 的 eclipse 项目中升级到 JPA 2 1 当我尝试执行以下操作时出现以下错误Run As Run on Server从日食内部 java lang N
  • 如何实现可运行队列

    我正在尝试实现一个可运行队列 在异步任务期间依次执行 意味着队列中的下一个将在另一个完成后执行 我编写了一个管理器来管理这些可运行对象和本身就是可运行对象的任务 然后 我获取异步任务中的第一个任务并运行它 希望它能够在队列中运行 但是它最终
  • 在java中查找OSX的版本

    我需要测试 java 中 osx 的版本是否 Try System getProperty os name and or System getProperty os version 它返回字符串 HERE https docs oracle
  • 如何将 java ArrayList 转换为等效的 double[] [重复]

    这个问题在这里已经有答案了 可能的重复 如何在 Java 中从 List 转换为 double https stackoverflow com questions 6018267 how to cast from listdouble to
  • Spring Service @Transactional 不回滚事务 Mybatis SqlSession

    目标是在失败时回滚所有 任何事务 但这并没有按预期工作 我们使用Spring MVC JMS Service Mybatis 在日志中 JMS 设置为回滚 但行已插入且未回滚 想知道我错过了什么或做错了什么吗 最近添加了 Transacti
  • 如何在android中播放内部和外部SD卡中的mp3文件?

    我正在开发一个 mp3 播放器应用程序 它可以播放内部 SD 卡内任何位置的 mp3 文件 我使用以下代码来获取内部存储中存在的 mp3 文件 ArrayList
  • 处理大数据表时应该如何使用Hibernate Mapping

    问题定义 我有一个包含大量数据 超过 100 000 行 的数据库表 表结构如下 AppID DocID DocStatus 1 100 0 1 101 1 2 200 0 2 300 1 每个 applicationID 可能有数千个文档
  • 如何制作一个向用户显示图像而不是文本的下拉列表?

    ObjectChoiceField 字段满足我的所有要求 但它并不漂亮 这就是我所拥有的 String pets Dog Cat Duck ObjectChoiceField dd new ObjectChoiceField My Pet
  • 更改 WireMock __files 目录

    来自docs http wiremock org docs stubbing 要从文件中读取正文内容 请将文件放在 files 下 目录 默认情况下 这应该位于 src test resources 下 从 JUnit 规则运行时 当独立运
  • 从 API Explorer 调用 API 方法时不允许使用范围

    我在 Google App Engine 中有一个奇怪的行为 我正在使用 Eclipse 和 Java 进行开发 特别是使用 Google Cloud Endpoints 我使用以下设置创建了一个示例 API 实际上 我正在使用许多其他示波
  • 如何在 JUnit 中缩短(或隐藏)包名称?

    我在 JUnit 中有很长的包名称 这使得很难看到正在运行哪些测试 不幸的是 使用 Eclipse 的 缩写包名称 不起作用 有没有办法隐藏或者最好缩短它们 None
  • 从 Java/Spring 检索 RabbitMQ 队列中未确认消息的数量

    有没有办法返回未确认的消息数 我正在使用此代码来获取队列中的消息数 DeclareOk declareOk amqpAdmin getRabbitTemplate execute new ChannelCallback
  • 计算事件之间的天数 - Android

    我一直在研究 Android API 并一直在寻找一种方法来计算当前日期和未来日期之间的天数 我对 android 还很陌生 而且我已经有几年没有做过 java 了 计算这个最简单的方法是什么 Thanks 最简单的方法是使用乔达时间 ht
  • 告诉 JAXB 使用注释将 解组为 Date 类

    将 JAXB 与 Java First 一起使用时 类型的字段 属性java util Date编组和解编为xs dateTime一切都按预期进行 但是如果字段 属性的类型是Object JAXB 解组xs dateTimeto XMLGr
  • 部署到 Glassfish 4.1 时 URL 模式无效

    如果用户已经通过身份验证 我有一个网络过滤器可以从登录和索引页面重定向 最初我有一个无效的 URL 模式 我修复了无效模式并尝试重新部署以接收以下内容 java lang IllegalArgumentException Invalid U
  • startDrag 方法 已弃用且无法编译程序

    startDrag android content ClipData android view View DragShadowBuilder java lang Object int 已弃用 如何解决这个问题而又不失去对旧版本的兼容性 还有
  • 运行外部进程的非阻塞线程

    我创建了一个 Java GUI 应用程序 它充当许多低级外部进程的包装器 该实用程序按原样运行 但迫切需要一项重大改进 我希望我的外部进程以非阻塞方式运行 这将允许我并行服务其他请求 简而言之 我希望能够在生成数据时处理来自外部进程的数据
  • 与 System.in.read() 一起使用的文件结尾/流键盘组合是什么

    如果这个小问题已经得到解答 我深表歉意 我无法在SO找到它 使用以下 Java 简单代码从 IDE 控制台读取行 Windows 7 和 Eclipse Kepler int v try while v System in read 1 S
  • 返回在 REST 控制器中包装 S3Object.getObjectContent() 的 ResponseEntity 是否安全?

    我正在开发一个 Spring Boot 应用程序 它应该允许用户通过指定的应用程序 REST 接口间接从 Amazon S3 下载文件 为此 我有一个 REST Controller 它向用户返回一个 InputStreamResource

随机推荐

  • 第二十一章、文件服务器之三: FTP 服务器

    FTP File Transfer Protocol 可说是最古老的协议之一了 主要是用来进行档案的传输 尤其是大型档案的传输使用 FTP 更是方便 不过 值得注意的是 使用 FTP 来传输时 其实是具有一定程度的 危险性 因为数据在因特网
  • 你可以简单的设计一下上面的订单管理系统吗

    当然可以 首先 订单管理系统通常包含以下几个主要功能 订单录入 用户可以在系统中输入新的订单信息 包括订单编号 订购商品的种类 数量 单价 总价等信息 订单查询 用户可以根据订单编号 商品名称 日期等信息查询订单 订单修改 用户可以修改已经
  • 编程网站:21 个学习网站推荐给你,大部分编程语言都在这里了

    本文精选了21个有关代码 编程 Java Python SQL Git 和Ruby on Rails学习的网站 这些网站为以下内容的学习提供了免费的优质资源 编程语言 Python和Java等 常用技术 SQL等 操作系统 Linux等 W
  • 编译器中和64位编程有关的预定义宏

    版权声明 本文为博主原创文章 未经博主允许不得转载 本文对分别测试VC MinGW GCC 三种编译器 32位和64位模式 共6种情况下 和64位编程有关的与预定义宏的值 对跨平台编程具有参考意义 Agner Fog 在他的 Calling
  • MyBatis学习(三)-- 实现关联查询

    文章目录 1 实现关联查询 1 1 创建教师表 1 2 创建班级表 1 3 创建学生表 2 创建与数据库表对应的实体类 2 1 创建教师实体类 2 2 创建学生实体类 2 3 创建班级实体类 3 创建班级映射器配置文件 4 修改配置文件 5
  • 【Linux初阶】Linux环境下的 git 使用

    hello 各位读者大大们你们好呀 系列专栏 Linux初阶 本篇内容 详细阐述git是什么 git的发展脉络 还有Linux环境下git工具的具体使用方法 作者简介 计算机海洋的新进船长一枚 请多多指教 目录 一 git是什么 二 git
  • 模块1--BH1750的应用(IIC)

    1 BH1750基本原理讲解 BH1750作为一款数字化的光照传感器 采用的是IIC接口 本篇文章主要是侧重BH1750的应用 关于IIC总线的时序原理 请大家自行学习 数字化的传感器 简单点理解即只要通信接口配置正确 即可读出数据 内部集
  • 微服务架构中不同微服务之间的接口调用

    假定系统管理微服务的实例名称为system 在系统管理中查询码表 api system codeTable queryDataDictionaryByDicCode 在自己的微服务中调用系统管理的查询码表接口写法如下 DataDiction
  • 初识OpenGL (-)VAO&VBO

    如何填充VBO 配置顶点属性指针以及如何把它们都储存到一个VAO里 step1 把颜色数据加进顶点数据中 eg 把颜色数据添加为3个float值至vertices数组 把三角形的三个角分别指定为红色 绿色和蓝色 float vertices
  • 批处理框架

    什么是批处理 在现代企业应用当中 面对复杂的业务以及海量的数据 除了通过庞杂的人机交互界面进行各种处理外 还有一类工作 不需要人工干预 只需要定期读入大批量数据 然后完成相应业务处理并进行归档 这类工作即为 批处理 为什么使用Spring
  • 数据分析和数据挖掘概述

    1 含义 数据挖掘 指从大量的数据中 通过统计学 人工智能 机器学习等方法 挖掘出未知的 且有价值的信息和知识的过程 数据分析 可分为广义的数据分析和狭义的数据分析 广义的数据分析就是包括狭义的数据分析和数据挖掘 而我们常说的数据分析指的是
  • 交叉编译工具的使用说明

    写在前面的话 由于已经学习了JZ2440V3开发板的裸机程序 想检验下学习成果 所以从今天开始把以前学的知识点在tiny4412开发板上面做个检验 裸机部分学习到把uboot移植完成就结束 然后 学习内核的驱动和其他子系统框架 言归正传 现
  • 阿里面试官:接口的幂等性怎么设计?

    一 什么是幂等 看一下维基百科怎么说的 幂等性 多次调用方法或者接口不会改变业务状态 可以保证重复调用的结果和单次调用的结果一致 二 使用幂等的场景 1 前端重复提交 用户注册 用户创建商品等操作 前端都会提交一些数据给后台服务 后台需要根
  • linux shell 正则表达式(BREs,EREs,PREs)差异比较

    http www cnblogs com chengmo archive 2010 10 10 1847287 html 正则表达式 在计算机科学中 是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串 在很多文本编辑器或其他
  • 笛卡尔树建树

    拿个单调队列维护 最后pop出来的就是它的左儿子 现在还在的 它是他的右儿子 int build int S N for int i 1 i lt n i while top T S top val lt T i val T i son 0
  • Markdown中显示矩阵运算过程

    发现这个神奇的用法 以后写博客就可以很好的演示矩阵乘法了 原文知乎 这里再分享一个可以把latex转成图片的在线网站quicklatex markdown 显示矩阵 from IPython display import display L
  • mysql锁总结

    参考文章 MySQL 死锁查询 事务与锁详解2 MySQL死锁系列 常见加锁场景分析 死锁的成因 场景以及死锁的避免 查询锁sql 1 查看当前的事务 SELECT FROM INFORMATION SCHEMA INNODB TRX 2
  • 解决centos下sudo运行tshark,写入文件显示:Permission denied.

    在 w时 需要把文件名写全 相对路径无权限 则需要写成绝对路径 比如 sudo tshark w home xxxx mypcap pcap 下面的不行 sudo tshark w mypcap pcap Permission denied
  • 走线和交互式布线_画PCB时,一些非常好的布线技巧

    画PCB时 一些非常好的布线技巧 布线是PCB设计过程中技巧最细 限定最高的 即使布了十几年布线的工程师也往往觉得自己不会布线 因为看到了形形色色的问题 知道了这根线布了出去就会导致什么恶果 所以 就变的不知道怎么布了 但是高手还是有的 他
  • spring cloud 2021.0.1升级踩坑记录

    一 版本说明 升级前的版本 spring boot 2 2 2 RELEASE spring cloud Hoxton SR1 spring cloud alibaba 2 2 0 RELEASE 升级后版本 spring boot 2 6