JeecgBoot框架升級(jí)至Spring?Boot3的實(shí)戰(zhàn)步驟
官方推出SpringBoot3版本:https://github.com/jeecgboot/jeecg-boot/tree/springboot3
本次更新由于屬于破壞式更新,有幾個(gè)生態(tài)內(nèi)的組件,逐步支持,以下為功能列表
- Online功能 (已支持)
- 積木報(bào)表功能(已支持)
- 儀表盤(pán)功能(已支持)
- spring cloud gateway 的 SentinelFilterContextConfig 過(guò)濾器
Spring Boot
從 2.7.10升級(jí)到3.1.5有以下幾個(gè)點(diǎn)需要注意。
- 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
除以上三點(diǎn)外,其它都是平滑升級(jí),不過(guò)這也只是相對(duì)于我們應(yīng)用Spring Boot的用戶(hù)來(lái)說(shuō)。不過(guò)對(duì)于第二點(diǎn),屬于是破壞性升級(jí)了,需要將項(xiàng)目中引用的javax.servlet替換成jakarta.servlet。
spring boot升級(jí)參考文檔:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide
spring cloud升級(jí)參考文檔:https://docs.spring.io/spring-cloud/docs/current/reference/html/
spring cloud alibaba升級(jí)參考文檔: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需要升級(jí),不過(guò)還好shiro官方給這個(gè)點(diǎn)提供了支持,以下是shiro的升級(jí)替換。
需要注意的是,spring boot 3.1.5對(duì)jedis的版本做了提升,提升后shiro無(wú)法兼容,所以只能在項(xiàng)目進(jìn)行降版本處理。
shiro升級(jí)參考文檔:http://www.dbjr.com.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 無(wú)法使用 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的依賴(lài) --> <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的依賴(lài)包 --> <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對(duì)于spring boot 3.X版本提供了支持,不過(guò)相當(dāng)于spring boot 2.X的版本來(lái)說(shuō),差異比較大,從springfox轉(zhuǎn)換成了springdoc,不能做到平滑升級(jí),以下是需要替換的注解列表.
knife4j升級(jí)參考文檔:
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")
同樣在初始化文檔對(duì)象上也有區(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 后臺(tái)服務(wù)API接口文檔") .version("1.0") .contact(new Contact().name("北京國(guó)炬信息技術(shù)有限公司").url("www.jeccg.com").email("jeecgos@163.com")) .description( "后臺(tái)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 后臺(tái)服務(wù)API接口文檔") .version("1.0") .contact(new Contact().name("北京國(guó)炬信息技術(shù)有限公司").url("www.jeccg.com").email("jeecgos@163.com")) .description( "后臺(tái)API接口") .termsOfService("NO terms of service") .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html")) ); }
升級(jí)的maven地址:
<dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId> <version>4.3.0</version> </dependency>
在knife4j 4.X版本中,首次在對(duì)swagger文檔與spring cloud gateway進(jìn)行了整合,提供完整的解決方案,做到了開(kāi)箱即用,以下是應(yīng)用案例,在jeecg中也得到了升級(jí)。
<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)平滑升級(jí)
以下為平滑升級(jí),即更換版本即可,不需要做任何調(diào)整,jeecg框架調(diào)整如下
<!-- druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-3-starter</artifactId> <version>1.2.20</version> </dependency> <!-- 動(dòng)態(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
把需要自動(dòng)加載的啟動(dòng)類(lèi)一行一個(gè)全限定名就可以了
替換原來(lái)的spring.factories
到此這篇關(guān)于JeecgBoot框架升級(jí)至Spring Boot3的實(shí)戰(zhàn)步驟的文章就介紹到這了,更多相關(guān)JeecgBoot升級(jí)至Spring Boot3內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Spring整合Mybatis 掃描注解創(chuàng)建Bean報(bào)錯(cuò)的解決方案
這篇文章主要介紹了Spring 整合Mybatis 掃描注解創(chuàng)建Bean報(bào)錯(cuò)的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-10-10Java判斷范圍型的數(shù)據(jù)是否存在重疊的方法
遇到了個(gè)問(wèn)題,同一天可以輸入多個(gè)時(shí)間段,但是每個(gè)時(shí)間段的時(shí)間不能出現(xiàn)重疊,這不就是判斷數(shù)據(jù)返回是否有重疊的變種嗎,所以本文給大家介紹了Java判斷范圍型的數(shù)據(jù)是否存在重疊的方法,需要的朋友可以參考下2024-07-07MyBatis中關(guān)于SQL的寫(xiě)法總結(jié)
這篇文章主要介紹了MyBatis中關(guān)于SQL的寫(xiě)法總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08Spring Boot集成Shiro實(shí)現(xiàn)動(dòng)態(tài)加載權(quán)限的完整步驟
這篇文章主要給大家介紹了關(guān)于Spring Boot集成Shiro實(shí)現(xiàn)動(dòng)態(tài)加載權(quán)限的完整步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09ShardingSphere jdbc集成多數(shù)據(jù)源的實(shí)現(xiàn)步驟
本文主要介紹了ShardingSphere jdbc集成多數(shù)據(jù)源的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-10-10java 驗(yàn)證用戶(hù)是否已經(jīng)登錄與實(shí)現(xiàn)自動(dòng)登錄方法詳解
本文主要介紹了java 驗(yàn)證用戶(hù)是否已經(jīng)登錄與實(shí)現(xiàn)自動(dòng)登錄的方法。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01java枚舉使用詳細(xì)介紹及實(shí)現(xiàn)
這篇文章主要介紹了java枚舉使用詳細(xì)介紹及實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2017-06-06