JeecgBoot框架升級至Spring?Boot3的實戰(zhàn)步驟
官方推出SpringBoot3版本:https://github.com/jeecgboot/jeecg-boot/tree/springboot3
本次更新由于屬于破壞式更新,有幾個生態(tài)內(nèi)的組件,逐步支持,以下為功能列表
- Online功能 (已支持)
- 積木報表功能(已支持)
- 儀表盤功能(已支持)
- spring cloud gateway 的 SentinelFilterContextConfig 過濾器
Spring Boot
從 2.7.10升級到3.1.5有以下幾個點需要注意。
- JDK版本支持從JDK 17-19版本
- javax.servlet切換到j(luò)akarta.servlet
- spring.redis配置切換為spring.data.redis
- Spring Cloud 2022.0.4
- Spring Cloud Alibaba 2022.0.0.0
除以上三點外,其它都是平滑升級,不過這也只是相對于我們應(yīng)用Spring Boot的用戶來說。不過對于第二點,屬于是破壞性升級了,需要將項目中引用的javax.servlet替換成jakarta.servlet。
spring boot升級參考文檔:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide
spring cloud升級參考文檔:https://docs.spring.io/spring-cloud/docs/current/reference/html/
spring cloud alibaba升級參考文檔:https://sca.aliyun.com/zh-cn/docs/2022.0.0.0/overview/version-explain
Shiro
前面講到由于Spring Boot內(nèi)部的servlet包換掉了,jeecg框架使用shiro以及spring boot集成,所以shiro需要升級,不過還好shiro官方給這個點提供了支持,以下是shiro的升級替換。
需要注意的是,spring boot 3.1.5對jedis的版本做了提升,提升后shiro無法兼容,所以只能在項目進(jìn)行降版本處理。
shiro升級參考文檔:http://chabaoo.cn/program/319485h0o.htm
<!--shiro--> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring-boot-starter</artifactId> <version>${shiro.version}</version> <exclusions> <exclusion> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> </exclusion> </exclusions> </dependency> <!-- shiro-redis --> <dependency> <groupId>org.crazycake</groupId> <artifactId>shiro-redis</artifactId> <version>${shiro-redis.version}</version> <exclusions> <exclusion> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> </exclusion> <exclusion> <artifactId>checkstyle</artifactId> <groupId>com.puppycrawl.tools</groupId> </exclusion> </exclusions> </dependency> <!-- shiro 無法使用 spring boot 3.X 自帶的jedis,降版本處理 --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <classifier>jakarta</classifier> <version>${shiro.version}</version> <!-- 排除仍使用了javax.servlet的依賴 --> <exclusions> <exclusion> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> </exclusion> <exclusion> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> </exclusion> </exclusions> </dependency> <!-- 引入適配jakarta的依賴包 --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <classifier>jakarta</classifier> <version>${shiro.version}</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-web</artifactId> <classifier>jakarta</classifier> <version>${shiro.version}</version> <exclusions> <exclusion> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> </exclusion> </exclusions> </dependency>
knife4j
knife4j對于spring boot 3.X版本提供了支持,不過相當(dāng)于spring boot 2.X的版本來說,差異比較大,從springfox轉(zhuǎn)換成了springdoc,不能做到平滑升級,以下是需要替換的注解列表.
knife4j升級參考文檔:
https://doc.xiaominfo.com/docs/quick-start/start-knife4j-version#22-spring-boot-3x
https://springdoc.org/#migrating-from-springfox
@Api
→@Tag
@ApiIgnore
→@Parameter(hidden = true)
or@Operation(hidden = true)
or@Hidden
@ApiImplicitParam
→@Parameter
@ApiImplicitParams
→@Parameters
@ApiModel
→@Schema
@ApiModelProperty(hidden = true)
→@Schema(accessMode = READ_ONLY)
@ApiModelProperty
→@Schema
@ApiOperation(value = "foo", notes = "bar")
→@Operation(summary = "foo", description = "bar")
@ApiParam
→@Parameter
@ApiResponse(code = 404, message = "foo")
→@ApiResponse(responseCode = "404", description = "foo")
同樣在初始化文檔對象上也有區(qū)別,以下前后替換
[@Bean](https://my.oschina.net/bean) public GroupedOpenApi swaggerOpenApi() { return GroupedOpenApi.builder() .group("default") .packagesToScan("org.jeecg") .build(); } [@Bean](https://my.oschina.net/bean) public OpenAPI customOpenAPI() { return new OpenAPI() .info(new Info() .title("JeecgBoot 后臺服務(wù)API接口文檔") .version("1.0") .contact(new Contact().name("北京國炬信息技術(shù)有限公司").url("www.jeccg.com").email("jeecgos@163.com")) .description( "后臺API接口") .termsOfService("NO terms of service") .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")) ); } // ---------------------------替換后--------------------- [@Bean](https://my.oschina.net/bean) public GroupedOpenApi swaggerOpenApi() { return GroupedOpenApi.builder() .group("default") .packagesToScan("org.jeecg") .build(); } [@Bean](https://my.oschina.net/bean) public OpenAPI customOpenAPI() { return new OpenAPI() .info(new Info() .title("JeecgBoot 后臺服務(wù)API接口文檔") .version("1.0") .contact(new Contact().name("北京國炬信息技術(shù)有限公司").url("www.jeccg.com").email("jeecgos@163.com")) .description( "后臺API接口") .termsOfService("NO terms of service") .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")) ); }
升級的maven地址:
<dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId> <version>4.3.0</version> </dependency>
在knife4j 4.X版本中,首次在對swagger文檔與spring cloud gateway進(jìn)行了整合,提供完整的解決方案,做到了開箱即用,以下是應(yīng)用案例,在jeecg中也得到了升級。
<dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-gateway-spring-boot-starter</artifactId> <version>4.3.0</version> </dependency>
spring boot 3.x 生態(tài)增強(qiáng)平滑升級
以下為平滑升級,即更換版本即可,不需要做任何調(diào)整,jeecg框架調(diào)整如下
<!-- druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-3-starter</artifactId> <version>1.2.20</version> </dependency> <!-- 動態(tài)數(shù)據(jù)源 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot3-starter</artifactId> <version>4.1.3</version> </dependency> <!-- spring boot-admin --> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-server</artifactId> <version>3.0.4</version> </dependency>
META-INF改造spring.factories
新建文件org.springframework.boot.autoconfigure.AutoConfiguration.imports
把需要自動加載的啟動類一行一個全限定名就可以了
替換原來的spring.factories
到此這篇關(guān)于JeecgBoot框架升級至Spring Boot3的實戰(zhàn)步驟的文章就介紹到這了,更多相關(guān)JeecgBoot升級至Spring Boot3內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Spring整合Mybatis 掃描注解創(chuàng)建Bean報錯的解決方案
這篇文章主要介紹了Spring 整合Mybatis 掃描注解創(chuàng)建Bean報錯的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10Java判斷范圍型的數(shù)據(jù)是否存在重疊的方法
遇到了個問題,同一天可以輸入多個時間段,但是每個時間段的時間不能出現(xiàn)重疊,這不就是判斷數(shù)據(jù)返回是否有重疊的變種嗎,所以本文給大家介紹了Java判斷范圍型的數(shù)據(jù)是否存在重疊的方法,需要的朋友可以參考下2024-07-07Spring Boot集成Shiro實現(xiàn)動態(tài)加載權(quán)限的完整步驟
這篇文章主要給大家介紹了關(guān)于Spring Boot集成Shiro實現(xiàn)動態(tài)加載權(quán)限的完整步驟,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09ShardingSphere jdbc集成多數(shù)據(jù)源的實現(xiàn)步驟
本文主要介紹了ShardingSphere jdbc集成多數(shù)據(jù)源的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-10-10java 驗證用戶是否已經(jīng)登錄與實現(xiàn)自動登錄方法詳解
本文主要介紹了java 驗證用戶是否已經(jīng)登錄與實現(xiàn)自動登錄的方法。具有一定的參考價值,下面跟著小編一起來看下吧2017-01-01