淺談Spring Boot、MyBatis、MyBatis-Plus 依賴(lài)版本對(duì)應(yīng)關(guān)系
在使用 Spring Boot、MyBatis 和 MyBatis-Plus 時(shí),確保它們的依賴(lài)版本兼容是項(xiàng)目正常運(yùn)行的關(guān)鍵。版本不兼容可能會(huì)導(dǎo)致諸如 sqlSessionFactory
、sqlSessionTemplate
未正確配置等錯(cuò)誤。因此,合理選擇各個(gè)依賴(lài)的版本尤為重要。以下是 Spring Boot 各個(gè)版本與 MyBatis 和 MyBatis-Plus 的版本對(duì)應(yīng)關(guān)系總結(jié)。
1. Spring Boot、MyBatis、MyBatis-Plus 依賴(lài)版本對(duì)應(yīng)關(guān)系表
Spring Boot 版本 | MyBatis 版本 | MyBatis-Plus 版本 | MyBatis-Plus Starter 版本 |
---|---|---|---|
2.7.x | 2.2.x | 3.4.x | 3.4.x |
3.0.x | 3.5.x | 3.5.x | 3.5.x |
3.1.x | 3.5.x | 3.5.x | 3.5.x |
3.2.x | 3.5.x | 3.5.x | 3.5.x |
2. 依賴(lài)選擇說(shuō)明
- MyBatis 版本:
- Spring Boot 2.x 版本推薦使用 MyBatis 2.x 系列。
- 從 Spring Boot 3.x 開(kāi)始,推薦使用 MyBatis 3.5.x 系列。它是 MyBatis 當(dāng)前最穩(wěn)定的版本,支持最新的 Java 17 特性以及 Spring Boot 3.x API。
- MyBatis-Plus 版本:
- MyBatis-Plus 3.4.x 適用于 Spring Boot 2.x 系列。
- MyBatis-Plus 3.5.x 是與 Spring Boot 3.x 系列兼容的最佳選擇。此版本優(yōu)化了對(duì) Java 17 和 Spring Boot 3.x 的支持,同時(shí)提高了性能和擴(kuò)展能力。
- MyBatis-Plus Starter 版本:
mybatis-plus-boot-starter
是 MyBatis-Plus 提供的整合 Starter,它包括了 MyBatis-Plus 所需的核心依賴(lài)和配置,可以簡(jiǎn)化項(xiàng)目配置過(guò)程。與 Spring Boot 2.x 使用 3.4.x 版本,與 Spring Boot 3.x 則使用 3.5.x 版本。
3. 版本選擇注意事項(xiàng)
- 兼容性問(wèn)題: 如果在項(xiàng)目中遇到
sqlSessionFactory
或sqlSessionTemplate
配置錯(cuò)誤,最常見(jiàn)的問(wèn)題是 MyBatis 或 MyBatis-Plus 的版本與 Spring Boot 版本不兼容。務(wù)必確保三者的版本處于同一兼容范圍內(nèi)。 - Spring Boot 3.x 的變化: Spring Boot 3.x 與之前的版本有較大改動(dòng),特別是在模塊化系統(tǒng)、Java 17 支持等方面。使用 MyBatis 和 MyBatis-Plus 的時(shí)候,一定要選擇 3.5.x 版本,以便與 Spring Boot 3.x 更好地配合。
4. 依賴(lài)示例(Spring Boot 3.1.x + MyBatis 3.5.x + MyBatis-Plus 3.5.x)
<dependencies> <!-- Spring Boot Web Starter --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- PostgreSQL 驅(qū)動(dòng) --> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> <version>42.6.2</version> </dependency> <!-- MyBatis Plus Starter --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.3.1</version> </dependency> <!-- Lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> </dependencies>
5. 常見(jiàn)問(wèn)題及解決方案
- 錯(cuò)誤提示:Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required: 這種報(bào)錯(cuò)通常是由于 MyBatis-Plus 和 Spring Boot 的版本不兼容造成的。解決方案是檢查并升級(jí) MyBatis-Plus 到與 Spring Boot 版本匹配的版本。
- 版本沖突: 如果項(xiàng)目中有其他依賴(lài)版本沖突,確保所有依賴(lài)庫(kù)使用的是兼容的版本,特別是在使用
mybatis-plus-boot-starter
時(shí),MyBatis 和 MyBatis-Plus 的版本必須匹配。
6. 總結(jié)
在整合 Spring Boot、MyBatis 和 MyBatis-Plus 時(shí):
- 確保所使用的 Spring Boot、MyBatis、MyBatis-Plus 和其 Starter 的版本是相互兼容的。
- 對(duì)于 Spring Boot 3.x,建議選擇 MyBatis 3.5.x 和 MyBatis-Plus 3.5.x,并確保所有依賴(lài)庫(kù)版本一致。
- 如果遇到錯(cuò)誤,首先檢查版本是否匹配,再排查具體配置問(wèn)題。
通過(guò)合理選擇依賴(lài)版本和 Starter,可以有效避免常見(jiàn)的配置錯(cuò)誤和兼容性問(wèn)題。
到此這篇關(guān)于淺談Spring Boot、MyBatis、MyBatis-Plus 依賴(lài)版本對(duì)應(yīng)關(guān)系的文章就介紹到這了,更多相關(guān)Spring Boot MyBatis MyBatis-Plus依賴(lài)版本對(duì)應(yīng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 5分鐘快速搭建SpringBoot3?+?MyBatis-Plus工程/項(xiàng)目的實(shí)現(xiàn)示例
- 解決mybatis-plus-boot-starter與mybatis-spring-boot-starter的錯(cuò)誤問(wèn)題
- Spring Boot 中整合 MyBatis-Plus詳細(xì)步驟(最新推薦)
- Spring?Boot?集成?MyBatis?全面講解(最新推薦)
- Spring Boot 中使用 Mybatis Plus的操作方法
- SpringBoot同時(shí)集成Mybatis和Mybatis-plus框架
- Springboot使用MybatisPlus實(shí)現(xiàn)mysql樂(lè)觀鎖
- Spring Boot Mybatis++ 2025詳解
相關(guān)文章
IDEA中Javaweb項(xiàng)目圖片加載不出來(lái)解決方案
在IDEA中能夠正常的預(yù)覽到圖片,但是在生成項(xiàng)目的war包時(shí),項(xiàng)目的目錄結(jié)構(gòu)卻會(huì)發(fā)生變化,所以無(wú)法訪(fǎng)問(wèn)圖片,本文主要介紹了IDEA中Javaweb項(xiàng)目圖片加載不出來(lái)解決方案,感興趣的可以了解一下2023-10-10springboot?maven?plugin報(bào)紅的解決辦法
本文主要介紹了springboot?maven?plugin報(bào)紅的解決辦法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07SpringCloud Gateway的路由,過(guò)濾器和限流解讀
這篇文章主要介紹了SpringCloud Gateway的路由,過(guò)濾器和限流解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02@RefreshScope在Quartz 觸發(fā)器類(lèi)導(dǎo)致異常問(wèn)題解決分析
這篇文章主要為大家介紹了@RefreshScope在Quartz 觸發(fā)器類(lèi)導(dǎo)致異常問(wèn)題解決分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02基于maven搭建一個(gè)ssm的web項(xiàng)目的詳細(xì)圖文教程
這篇文章主要介紹了基于maven搭建一個(gè)ssm的web項(xiàng)目的詳細(xì)教程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09springboot實(shí)現(xiàn)公眾號(hào)接收回復(fù)消息和超過(guò)5秒被動(dòng)回復(fù)消息
本文主要介紹了springboot實(shí)現(xiàn)公眾號(hào)接收回復(fù)消息和超過(guò)5秒被動(dòng)回復(fù)消息,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-05-05