Spring Boot 2.x/3.x/4.x 版本兼容的最新MyBatis-Plus依賴
背景
在 Spring Boot 最新的 4.0.3 版本(截止 2026 年 3 月 7 日)中,使用 MyBatis-Plus,在啟動(dòng)項(xiàng)目時(shí),有如下報(bào)錯(cuò):
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v4.0.3) 2026-03-07T17:58:14.685+08:00 INFO 3028 --- [backend] [ main] com.sun3285.backend.BackendApplication : Starting BackendApplication using Java 17.0.9 with PID 3028 (K:\項(xiàng)目\warehouse\backend\target\classes started by Sun3285 in K:\項(xiàng)目\warehouse) 2026-03-07T17:58:14.687+08:00 INFO 3028 --- [backend] [ main] com.sun3285.backend.BackendApplication : No active profile set, falling back to 1 default profile: "default" 2026-03-07T17:58:14.994+08:00 WARN 3028 --- [backend] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'userMapper' defined in file [K:\項(xiàng)目\warehouse\backend\target\classes\com\sun3285\backend\mapper\UserMapper.class]: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String 2026-03-07T17:58:14.997+08:00 INFO 3028 --- [backend] [ main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2026-03-07T17:58:15.005+08:00 ERROR 3028 --- [backend] [ main] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'userMapper' defined in file [K:\項(xiàng)目\warehouse\backend\target\classes\com\sun3285\backend\mapper\UserMapper.class]: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:857) ~[spring-beans-7.0.5.jar:7.0.5] at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:740) ~[spring-beans-7.0.5.jar:7.0.5] at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAnnotationOnBean(DefaultListableBeanFactory.java:811) ~[spring-beans-7.0.5.jar:7.0.5] at org.springframework.boot.sql.init.dependency.AnnotationDependsOnDatabaseInitializationDetector.detect(AnnotationDependsOnDatabaseInitializationDetector.java:36) ~[spring-boot-sql-4.0.3.jar:4.0.3] at org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer$DependsOnDatabaseInitializationPostProcessor.detectDependsOnInitializationBeanNames(DatabaseInitializationDependencyConfigurer.java:155) ~[spring-boot-sql-4.0.3.jar:4.0.3] at org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer$DependsOnDatabaseInitializationPostProcessor.postProcessBeanFactory(DatabaseInitializationDependencyConfigurer.java:118) ~[spring-boot-sql-4.0.3.jar:4.0.3] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:363) ~[spring-context-7.0.5.jar:7.0.5] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:197) ~[spring-context-7.0.5.jar:7.0.5] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:795) ~[spring-context-7.0.5.jar:7.0.5] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:603) ~[spring-context-7.0.5.jar:7.0.5] at org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-web-server-4.0.3.jar:4.0.3] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:756) ~[spring-boot-4.0.3.jar:4.0.3] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:445) ~[spring-boot-4.0.3.jar:4.0.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:321) ~[spring-boot-4.0.3.jar:4.0.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1365) ~[spring-boot-4.0.3.jar:4.0.3] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-4.0.3.jar:4.0.3] at com.sun3285.backend.BackendApplication.main(BackendApplication.java:12) ~[classes/:na] Process finished with exit code 1
借助大模型,問題定位在:Invalid value type for attribute 'factoryBeanObjectType': java.lang.String。
根本原因?yàn)椋?strong>MyBatis-Plus 版本與 Spring Boot 4.0.3 不兼容。
此時(shí),pom.xml 文件中,MyBatis-Plus 的依賴如下:
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.16</version>
<scope>compile</scope>
</dependency>
通過查閱資料,將 MyBatis-Plus 版本與 Spring Boot 版本進(jìn)行兼容后,啟動(dòng)項(xiàng)目無報(bào)錯(cuò),運(yùn)行成功。
借此機(jī)會(huì),以下對(duì)分別與 Spring Boot 2.x/3.x/4.x 版本兼容的最新 MyBatis-Plus 依賴(截止 2026 年 3 月 7 日)進(jìn)行總結(jié)。
Spring Boot 2.x 與 MyBatis-Plus 兼容
在 pom.xml 文件中,需要引入以下 MyBatis-Plus 的依賴(2026 年 1 月 11 日發(fā)布):
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.16</version>
<scope>compile</scope>
</dependency>
Spring Boot 3.x 與 MyBatis-Plus 兼容
在 pom.xml 文件中,需要引入以下 MyBatis-Plus 的依賴(2026 年 1 月 11 日發(fā)布):
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.16</version>
<scope>compile</scope>
</dependency>
Spring Boot 4.x 與 MyBatis-Plus 兼容
在 pom.xml 文件中,需要引入以下 MyBatis-Plus 的依賴(2026 年 1 月 11 日發(fā)布):
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot4-starter</artifactId>
<version>3.5.16</version>
<scope>compile</scope>
</dependency>
到此這篇關(guān)于Spring Boot 2.x/3.x/4.x 版本兼容的最新MyBatis-Plus依賴的文章就介紹到這了,更多相關(guān)Spring Boot 版本兼容MyBatis-Plus 依賴內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java+mysql本地圖片上傳數(shù)據(jù)庫(kù)及下載示例
本篇文章主要介紹了Java+mysql本地圖片上傳數(shù)據(jù)庫(kù)及下載示例,具有一定的參加價(jià)值,有興趣的可以了解一下。2017-01-01
Java?Post請(qǐng)求發(fā)送form-data表單參數(shù)詳細(xì)示例代碼
POST請(qǐng)求是一種常見的網(wǎng)絡(luò)通信操作,用于向服務(wù)器發(fā)送數(shù)據(jù),這種請(qǐng)求通常用于上傳文件或者提交包含大量數(shù)據(jù)的表單,這篇文章主要介紹了Java?Post請(qǐng)求發(fā)送form-data表單參數(shù)的相關(guān)資料,需要的朋友可以參考下2025-07-07
Mybatis配置之<environments>配置元素詳解
這篇文章主要介紹了Mybatis配置之<environments>配置元素,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
深入探究SpringBoot可以同時(shí)處理多少請(qǐng)求
SpringBoot是一款非常流行的Java后端框架,它可以幫助開發(fā)人員快速構(gòu)建高效的Web應(yīng)用程序,但是,許多人對(duì)于SpringBoot能夠同時(shí)處理多少請(qǐng)求的疑問仍然存在,在本篇文章中,我們將深入探討這個(gè)問題,需要的朋友可以參考下2023-07-07
java實(shí)現(xiàn)隨機(jī)森林RandomForest的示例代碼
本篇文章主要介紹了java實(shí)現(xiàn)隨機(jī)森林RandomForest的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
IDEA2025.1如何取消代碼自動(dòng)補(bǔ)全
這篇文章主要介紹了IDEA2025.1如何取消代碼自動(dòng)補(bǔ)全的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-06-06
Java中類轉(zhuǎn)json的基類實(shí)現(xiàn)
這篇文章主要介紹了Java中類轉(zhuǎn)json的基類實(shí)現(xiàn),需要的朋友可以參考下2021-01-01
Java連接PostgreSql數(shù)據(jù)庫(kù)及基本使用方式
這篇文章主要介紹了Java連接PostgreSql數(shù)據(jù)庫(kù)及基本使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-03-03

