前言
Spring Boot 3.0.0 GA版已經(jīng)發(fā)布,好多人也開始嘗試升級,有人測試升級后,啟動(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 倉庫。
在你的maven倉庫中加入如下配置,我是加在了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 開始使用了Java 17,將java版本調(diào)整到>17,為了不必要的麻煩,就選17IDEA選擇17,并在pom.xml文件中指定版本:
<java.version>17</java.version>
到這里我們的common 包是能正常編譯了。
接下來是服務(wù)的配置
同樣調(diào)整Spring Boot、Spring Cloud、Java的版本,同common的配置。
碰到如下的幾個(gè)問題:
找不到hystrix的依賴問題
:
升級后找不到hystrix的版本,官網(wǎng)也找不到,這里我顯式指定了版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
rabbitmq問題
:
相關(guān)的配置丟失,比如如下圖,這邊進(jìn)行適當(dāng)調(diào)整或者直接注釋解決。TypeVariableImpl丟失問題
:
原來服務(wù)中引入了sun.reflect.generics.reflectiveObjects.TypeVariableImpl
,現(xiàn)在17中已經(jīng)被隱藏?zé)o法直接使用,這邊為了能夠先啟動(dòng),暫時(shí)注釋,后面再想辦法。
Log 異常問題
:
由于之前我們項(xiàng)目中歷史原因,既有用log4j
,也有用logback
,升級后已經(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問題
:
使用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)
通過上述配置調(diào)整后,能編譯成功,但是無法啟動(dòng),控制沒有任何日志,初步懷疑還是log依賴問題,由于時(shí)間關(guān)系,沒有再繼續(xù),問題留到以后再弄,后面有新進(jìn)展,會(huì)持續(xù)更新該文。
javax 的依賴都變成jakarta
:
比如原來基于javax.validation包中的驗(yàn)證,javax.validation.constraints.NotNull此類的都需要調(diào)整
Spring Boot 3.0后,很多starter不能用:
Spring Boot 3.0后,以前的spring.factories
不能用了,
只能使用META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
,對于一些還沒改造的starter都無法使用,目前mybatisplus 已經(jīng)有支持3.0 的 SNAPSHOT版本,其他的druid、nacos 等還適配3.0,要等等了。但我怎么會(huì)坐以待斃,我嘗試自己改造中間件的starter,可還是報(bào)錯(cuò)
Failed to instantiate [org.springframework.boot.env.EnvironmentPostProcessor]: Specified class is an interface
作者其他文章:
Grafana 系列文章,版本:OOS v9.3.1(更新中)文章來源:http://www.zghlxwxcb.cn/news/detail-786629.html
- Grafana 的介紹和安裝
- Grafana監(jiān)控大屏配置參數(shù)介紹(一)
- Grafana監(jiān)控大屏配置參數(shù)介紹(二)
- Grafana監(jiān)控大屏可視化圖表
Spring Boot Admin 2 系列文章:文章來源地址http://www.zghlxwxcb.cn/news/detail-786629.html
- Spring Boot Admin 參考指南
- SpringBoot Admin服務(wù)離線、不顯示健康信息的問題
- Spring Boot Admin2 @EnableAdminServer的加載
- Spring Boot Admin2 AdminServerAutoConfiguration詳解
- Spring Boot Admin2 實(shí)例狀態(tài)監(jiān)控詳解
- Spring Boot Admin2 自定義JVM監(jiān)控通知
- Spring Boot Admin2 自定義異常監(jiān)控
- Spring Boot Admin 監(jiān)控指標(biāo)接入Grafana可視化
到了這里,關(guān)于Spring Boot 3.x微服務(wù)升級經(jīng)歷的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!