Spring Boot 2.x/3.x/4.x 版本兼容的最新MyBatis-Plus依赖

 更新时间:2026年03月13日 08:24:37   作者:Sun 3285  
本文主要介绍了Spring Boot 2.x/3.x/4.x 版本兼容的最新MyBatis-Plus依赖,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

背景

在 Spring Boot 最新的 4.0.3 版本(截止 2026 年 3 月 7 日)中,使用 MyBatis-Plus,在启动项目时,有如下报错:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: 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:\项目\warehouse\backend\target\classes started by Sun3285 in K:\项目\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:\项目\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:\项目\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

根本原因为:MyBatis-Plus 版本与 Spring Boot 4.0.3 不兼容

此时,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 版本进行兼容后,启动项目无报错,运行成功

借此机会,以下对分别与 Spring Boot 2.x/3.x/4.x 版本兼容的最新 MyBatis-Plus 依赖(截止 2026 年 3 月 7 日)进行总结。

Spring Boot 2.x 与 MyBatis-Plus 兼容

pom.xml 文件中,需要引入以下 MyBatis-Plus 的依赖(2026 年 1 月 11 日发布):

<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 日发布):

<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 日发布):

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-spring-boot4-starter</artifactId>
    <version>3.5.16</version>
    <scope>compile</scope>
</dependency>

到此这篇关于Spring Boot 2.x/3.x/4.x 版本兼容的最新MyBatis-Plus依赖的文章就介绍到这了,更多相关Spring Boot 版本兼容MyBatis-Plus 依赖内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • java从控制台接收一个数字的实例详解

    java从控制台接收一个数字的实例详解

    这篇文章主要介绍了java从控制台接收一个数字的实例详解的相关资料,这里提供实例代码,注释说明清晰,需要的朋友可以参考下
    2017-07-07
  • Spring细数两种代理模式之静态代理和动态代理概念及使用

    Spring细数两种代理模式之静态代理和动态代理概念及使用

    代理是一种设计模式,提供了对目标对象另外的访问方式,即通过代理对象访问目标对象。可以不修改目标对象,对目标对象功能进行拓展。在我们学习Spring的时候就会发现,AOP(面向切面编程)的底层就是代理
    2023-02-02
  • SpringBoot中加载与Bean处理的细节剖析教程

    SpringBoot中加载与Bean处理的细节剖析教程

    这篇文章主要为大家详细介绍了SpringBoot中加载与Bean处理的细节剖析,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下
    2025-08-08
  • 为什么不要使用 async void的原因分析

    为什么不要使用 async void的原因分析

    这篇文章主要介绍了为什么不要使用 async void的原因分析及解决方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-04-04
  • 使用webmagic实现爬虫程序示例分享

    使用webmagic实现爬虫程序示例分享

    这篇文章主要介绍了使用webmagic实现爬虫程序示例,需要的朋友可以参考下
    2014-04-04
  • 如何解决无法获取到Nacos配置中心的配置问题

    如何解决无法获取到Nacos配置中心的配置问题

    这篇文章主要介绍了如何解决无法获取到Nacos配置中心的配置问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2025-06-06
  • Java发送form-data请求实现文件上传

    Java发送form-data请求实现文件上传

    这篇文章主要为大家详细介绍了Java发送form-data请求实现文件上传,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-06-06
  • 如何将eclipse项目导入到idea的方法步骤(图文)

    如何将eclipse项目导入到idea的方法步骤(图文)

    这篇文章主要介绍了如何将eclipse项目导入到idea的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03
  • 东八区springboot如何配置序列化

    东八区springboot如何配置序列化

    本文主要介绍了东八区springboot如何配置序列化,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-04-04
  • Java基于fork/koin类实现并发排序

    Java基于fork/koin类实现并发排序

    这篇文章主要介绍了Java基于fork/koin类实现并发排序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-02-02

最新评论