分享Spring Boot 3.x微服務(wù)升級(jí)歷程
前言
Spring Boot 3.0.0 GA版已經(jīng)發(fā)布,好多人也開(kāi)始嘗試升級(jí),有人測(cè)試升級(jí)后,啟動(dòng)速度確實(shí)快了不少,如下為網(wǎng)絡(luò)截圖,于是我也按捺不住的想嘗試下。

歷程
首先就是要把Spring Boot、Spring Cloud 相關(guān)的依賴升一下
Spring Boot:3.0.0
Spring Cloud:2022.0.0-RC2
統(tǒng)一依賴版本管理:
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>2022.0.0-RC2</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.0.0</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
現(xiàn)在還不能下載Spring 相關(guān)依賴包,需要加入Spring 倉(cāng)庫(kù)。
在你的maven倉(cāng)庫(kù)中加入如下配置,我是加在了pom.xml中
<repository> <id>netflix-candidates</id> <name>Netflix Candidates</name> <url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository>
另外Spring Boot 3.X 開(kāi)始使用了Java 17,將java版本調(diào)整到>17,為了不必要的麻煩,就選17IDEA選擇17,并在pom.xml文件中指定版本:
<java.version>17</java.version>
到這里我們的common 包是能正常編譯了。
接下來(lái)是服務(wù)的配置
同樣調(diào)整Spring Boot、Spring Cloud、Java的版本,同common的配置。
碰到如下的幾個(gè)問(wèn)題:
找不到hystrix的依賴問(wèn)題:
升級(jí)后找不到hystrix的版本,官網(wǎng)也找不到,這里我顯式指定了版本
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> <version>2.2.9.RELEASE</version> </dependency>
rabbitmq問(wèn)題:
相關(guān)的配置丟失,比如如下圖,這邊進(jìn)行適當(dāng)調(diào)整或者直接注釋解決。


TypeVariableImpl丟失問(wèn)題:
原來(lái)服務(wù)中引入了sun.reflect.generics.reflectiveObjects.TypeVariableImpl,現(xiàn)在17中已經(jīng)被隱藏?zé)o法直接使用,這邊為了能夠先啟動(dòng),暫時(shí)注釋,后面再想辦法。
Log 異常問(wèn)題:
由于之前我們項(xiàng)目中歷史原因,既有用log4j,也有用logback,升級(jí)后已經(jīng)不行,提示沖突,報(bào)錯(cuò)如下
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.helpers.NOPLoggerFactory loaded from file:/Users/chenjujun/.m2/repository/org/slf4j/slf4j-api/1.7.0/slf4j-api-1.7.0.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.helpers.NOPLoggerFactory
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:713)
at org.springframework.util.Assert.isInstanceOf(Assert.java:632)
意思是,要么移除Logback,要么解決slf4j-api的沖突依賴,這里兩種方式都嘗試了,slf4j-api依賴的地方太多,后面移除了Logback。
要排除依賴一個(gè)好辦法:使用Maven Helper插件

logback依賴:
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.8</version> </dependency>
Apollo問(wèn)題:
使用Apollo會(huì)提示該錯(cuò)誤,需要在啟動(dòng)中加入--add-opens java.base/java.lang=ALL-UNNAMED
Caused by: com.ctrip.framework.apollo.exceptions.ApolloConfigException: Unable to load instance for com.ctrip.framework.apollo.spring.config.ConfigPropertySourceFactory!
at com.ctrip.framework.apollo.spring.util.SpringInjector.getInstance(SpringInjector.java:40)
at com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer.<init>(ApolloApplicationContextInitializer.java:66)
... 16 more
Caused by: com.ctrip.framework.apollo.exceptions.ApolloConfigException: Unable to initialize Apollo Spring Injector!
at com.ctrip.framework.apollo.spring.util.SpringInjector.getInjector(SpringInjector.java:24)
at com.ctrip.framework.apollo.spring.util.SpringInjector.getInstance(SpringInjector.java:37)
... 17 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @16612a51
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at com.google.inject.internal.cglib.core.$ReflectUtils$1.run(ReflectUtils.java:52)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:42)
通過(guò)上述配置調(diào)整后,能編譯成功,但是無(wú)法啟動(dòng),控制沒(méi)有任何日志,初步懷疑還是log依賴問(wèn)題,由于時(shí)間關(guān)系,沒(méi)有再繼續(xù),問(wèn)題留到以后再弄,后面有新進(jìn)展,會(huì)持續(xù)更新該文。

到此這篇關(guān)于Spring Boot 3.x微服務(wù)升級(jí)經(jīng)歷的文章就介紹到這了,更多相關(guān)Spring Boot 3.x微服務(wù)升級(jí)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 關(guān)于SpringBoot3.x中spring.factories功能被移除的解決方案
- 淺析SpringBoot微服務(wù)中異步調(diào)用數(shù)據(jù)提交數(shù)據(jù)庫(kù)的問(wèn)題
- 使用Spring?Boot+gRPC構(gòu)建微服務(wù)并部署的案例詳解
- 教你在Spring Boot微服務(wù)中集成gRPC通訊的方法
- SpringBoot+Nacos+Kafka微服務(wù)流編排的簡(jiǎn)單實(shí)現(xiàn)
- SpringBoot+SpringCloud用戶信息微服務(wù)傳遞實(shí)現(xiàn)解析
- SpringBoot集成gRPC微服務(wù)工程搭建實(shí)踐的方法
- Spring Boot 快速搭建微服務(wù)框架詳細(xì)教程
相關(guān)文章
Java Agent 動(dòng)態(tài)修改字節(jié)碼詳情
這篇文章主要介紹了Java Agent動(dòng)態(tài)修改字節(jié)碼的相關(guān)資料,需要的朋友可以參考下面文章具體的內(nèi)容2021-09-09
RestTemplate的DELETE及PUT等請(qǐng)求方法使用精講
這篇文章主要為大家介紹了RestTemplate的DELETE及PUT等請(qǐng)求方法的使用精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-03-03
Java實(shí)現(xiàn)文件上傳到服務(wù)器本地并通過(guò)url訪問(wèn)的方法步驟
最近項(xiàng)目中使用到了文件上傳到服務(wù)器的功能,下面這篇文章主要給大家介紹了關(guān)于Java實(shí)現(xiàn)文件上傳到服務(wù)器本地并通過(guò)url訪問(wèn)的方法步驟,文中通過(guò)圖文以及實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
Spring Security的持久化用戶和授權(quán)實(shí)現(xiàn)方式
文章介紹了如何使用JdbcUserDetailsManager實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀取用戶,并展示了如何配置SpringSecurity進(jìn)行授權(quán)管理,通過(guò)創(chuàng)建數(shù)據(jù)庫(kù)表、配置數(shù)據(jù)庫(kù)連接和修改SecurityConfig,實(shí)現(xiàn)了用戶權(quán)限的控制2025-02-02
StreamAPI多次消費(fèi)一個(gè)stream代碼實(shí)例
這篇文章主要介紹了StreamAPI多次消費(fèi)一個(gè)stream代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04
java實(shí)現(xiàn)String字符串處理各種類型轉(zhuǎn)換
在日常的程序開(kāi)發(fā)中,經(jīng)常會(huì)涉及到不同類型之間的轉(zhuǎn)換,本文主要介紹了String字符串處理各種類型轉(zhuǎn)換,具有一定的參考價(jià)值,感興趣的可以了解一下2023-10-10
SpringBoot實(shí)現(xiàn)對(duì)Http接口進(jìn)行監(jiān)控的代碼
Spring Boot Actuator是Spring Boot提供的一個(gè)模塊,用于監(jiān)控和管理Spring Boot應(yīng)用程序的運(yùn)行時(shí)信息,本文將介紹一下Spring Boot Actuator以及代碼示例,以及如何進(jìn)行接口請(qǐng)求監(jiān)控,需要的朋友可以參考下2024-07-07
詳解eclipse項(xiàng)目中的.classpath文件原理
這篇文章介紹了eclipse項(xiàng)目中的.classpath文件的原理,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-12-12
關(guān)于kafka消費(fèi)不到遠(yuǎn)程bootstrap-server?數(shù)據(jù)的問(wèn)題
很多朋友遇到kafka消費(fèi)不到遠(yuǎn)程bootstrap-server?數(shù)據(jù)的問(wèn)題,怎么解決這個(gè)問(wèn)題,很多朋友不知所措,下面小編給大家?guī)?lái)了關(guān)于kafka消費(fèi)不到遠(yuǎn)程bootstrap-server?數(shù)據(jù)的問(wèn)題及解決方法,感興趣的朋友跟隨小編一起看看吧2021-11-11
一文掌握Spring?中?@Component?和?@Bean?區(qū)別(最新推薦)
?@Component?用于標(biāo)識(shí)一個(gè)普通的類,@Bean用于配置類里面,在方法上面聲明和配置?Bean?對(duì)象,這篇文章主要介紹了Spring?中?@Component?和?@Bean?區(qū)別(最新推薦),需要的朋友可以參考下2024-04-04

