SpringCloud 微服务集群升级记录(1.5.x-2.7.18)

本文记录了一次从Spring Boot 1.5.x和Spring Cloud旧版本到2.7.18的升级过程,包括遇到的如Mysql驱动更新、配置过期、循环依赖等问题及解决方案,还涉及Eureka、RabbitMQ、Nacos等组件的调整,以及Spring Boot 3.x系列文章的推荐。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

前段时间,因项目被扫出大量漏洞,全是因为依赖版本过低,存在高中危漏洞需要升级。正好本来也有规划集群升级,因为工作量大迟迟落实不了,正好有这次修漏洞的机会,升级微服务集群。这篇文章主要记录了本人的升级记录,遇到的问题解决方法,仅供参考。

项目背景

项目微服务技术栈:Spring Boot 1.5.x 、Spring Cloud、Kafka、RabbitMq、Mysql、Eureka、Apollo、Nacos。Spring Boot 是1.5.x 版本非常老旧,Spring Cloud 版本也早就停更。根据Nacos的兼容情况,Spring Boot 的版本为2.6.13,但目前最新版是2.7.18,由于3.x跟2.x区别较大,因此决定使用2.7.18试试,Spring Cloud 版本为2021.0.5.0。

在这里插入图片描述

升级记录

在xml中加入依赖,过期的配置会提示:

<dependency>
   
2025-03-11 15:13:28.185 INFO 1232 --- [ main] com.aleks.MainApplication : Starting MainApplication using Java 1.8.0_241 on AlekEnvy with PID 1232 (E:\workspace\IdeaProjects\demo\deploy\main-deploy\target\classes started by Aleks in E:\workspace\IdeaProjects\demo) 2025-03-11 15:13:28.190 INFO 1232 --- [ main] com.aleks.MainApplication : No active profile set, falling back to 1 default profile: "default" 2025-03-11 15:13:28.191 DEBUG 1232 --- [ main] o.s.boot.SpringApplication : Loading source class javafx.application.Application 2025-03-11 15:13:28.211 DEBUG 1232 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@78d6692f 2025-03-11 15:13:28.283 WARN 1232 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.context.MissingWebServerFactoryBeanException: No qualifying bean of type 'org.springframework.boot.web.servlet.server.ServletWebServerFactory' available: Unable to start AnnotationConfigServletWebServerApplicationContext due to missing ServletWebServerFactory bean 2025-03-11 15:13:28.309 DEBUG 1232 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : Application failed to start due to an exception org.springframework.boot.web.context.MissingWebServerFactoryBeanException: No qualifying bean of type 'org.springframework.boot.web.servlet.server.ServletWebServerFactory' available: Unable to start AnnotationConfigServletWebServerApplicationContext due to missing ServletWebServerFactory bean at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:212) ~[spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.7.18.jar:2.7.18] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:585) ~[spring-context-5.3.31.jar:5.3.31] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:409) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300) [spring-boot-2.7.18.jar:2.7.18] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1289) [spring-boot-2.7.18.jar:2.7.18] at com.aleks.MainApplication.main(MainApplication.java:10) [classes/:na] 2025-03-11 15:13:28.311 ERROR 1232 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context. Action: Check your application's dependencies for a supported servlet web server. Check the configured web application type. 与目标VM断开连接, 地址为: ''127.0.0.1:60906',传输: '套接字'', 传输: '{1}' 进程已结束,退出代码1
03-12
<think>嗯,用户给了一段Spring Boot应用的错误日志,看起来是启动失败的问题。我需要仔细分析日志内容,找出问题所在,然后给出解决方案。 首先,错误信息里提到“No qualifying bean of type 'ServletWebServerFactory'”,这说明Spring Boot在启动时没有找到合适的ServletWebServerFactory bean。这个bean通常是内嵌的Web服务器(比如Tomcat、Jetty或Undertow)自动配置的。所以可能的原因有几个:依赖缺失、错误的配置,或者应用类型设置不对。 接下来看日志中的细节。用户使用的是Spring Boot 2.7.18版本,Java 1.8。应用启动时没有激活任何profile,所以用的是默认配置。错误发生在创建Web服务器的时候,因为缺少ServletWebServerFactory。这说明Spring Boot没有自动配置Web服务器,可能相关的依赖没有被引入。 可能的第一个原因是依赖中没有包含Web starter。比如,如果是用Maven,用户可能没有添加spring-boot-starter-web依赖。或者他们可能错误地排除了Tomcat,导致没有可用的Web服务器工厂。这时候需要检查pom.xml或build.gradle文件,确保有正确的依赖。 第二个可能性是应用类型配置错误。Spring Boot支持不同的应用类型,比如Web应用、非Web应用。如果主类配置了SpringApplication并设置了非Web环境,比如SpringApplication.setWebApplicationType(WebApplicationType.NONE),就会导致不加载Web相关的配置。这时候需要检查主类中的设置,确保应用类型正确。 另外,用户可能在依赖中排除了Tomcat,但没有添加其他服务器的依赖。比如,排除了Tomcat后,如果没有引入Jetty或Undertow的starter,就会找不到Web服务器工厂。这时候需要检查依赖中的排除项,并添加替代的服务器依赖。 还有一个可能是使用了错误的Spring Boot版本,或者依赖冲突导致自动配置没有生效。这时候可以检查依赖树,看看是否有冲突或者版本不兼容的问题。但根据日志中的版本,2.7.18是比较新的,所以可能性较低。 用户的日志中还提到“No active profile set”,但这不是导致这个错误的主要原因,不过配置正确的profile有时也可能影响依赖加载,但这里应该不是关键问题。 总结下来,最可能的情况是缺少Web依赖或者排除了Tomcat而没有替换。需要指导用户检查依赖文件,确认是否添加了spring-boot-starter-web,或者是否有排除Tomcat的情况,并确保应用类型正确设置为Web应用。</think>这是一个典型的Spring Boot应用启动失败的日志。我们可以分步骤分析问题原因和解决方案: **错误核心信息分析:** $$ \text{No qualifying bean of type 'org.springframework.boot.web.servlet.server.ServletWebServerFactory'} $$ 这个错误表示Spring Boot无法找到创建Web服务器所需的工厂类。其根本原因是项目缺少Web服务器依赖。 **根本原因分析流程:** 1. **依赖缺失检查** - 缺少`spring-boot-starter-web`依赖(最常见原因) - 错误排除了Tomcat依赖(如使用`spring-boot-starter`但排除了Tomcat) 2. **应用类型验证** - 检查是否错误设置了`SpringApplication.setWebApplicationType(WebApplicationType.NONE)` - 确认主类是否继承了错误的基础类(如`SpringBootServletInitializer`) 3. **依赖冲突排查** - 检查`pom.xml`/`build.gradle`中是否包含以下必要依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` **解决方案步骤:** 1. **添加Web依赖(Maven示例)** ```xml <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> ``` 2. **验证依赖排除情况** 检查是否在依赖中排除了Tomcat: ```xml <exclusions> <exclusion> <!-- 如果存在此排除需要移除或添加替代服务器 --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> ``` 3. **检查应用入口类** 确保主类符合标准Spring Boot结构: ```java @SpringBootApplication public class MainApplication { public static void main(String[] args) { SpringApplication.run(MainApplication.class, args); // 确保使用标准启动方式 } } ``` **数学表达式辅助理解:** 当Spring Boot检测到classpath中存在Web依赖时,会自动创建: $$ \text{Web依赖} \in \text{classpath} \Rightarrow \text{自动配置ServletWebServerFactory} $$ **附加验证方法:** 执行以下命令检查依赖树: ```shell mvn dependency:tree | find "tomcat" ``` 期望输出应包含: $$ \text{org.springframework.boot:spring-boot-starter-tomcat:jar} $$ **典型误操作案例:** 当使用`spring-boot-starter`基础依赖但未添加Web组件时,满足: $$ \text{spring-boot-starter} \cap \neg \text{spring-boot-starter-web} \Rightarrow \text{无Web服务器} $$ 按照上述步骤排查后,应用应该能正常启动Web服务器。如果问题仍未解决,建议检查IDE的依赖缓存(执行`mvn clean install -U`强制更新依赖)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿提说说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值