SpringBoot3整合Mybatis-Plus与PageHelper包冲突解决

😊 @ 作者: 一恍过去
🎊 @ 社区: Java技术栈交流
🎉 @ 主题: SpringBoot3整合Mybatis-Plus与PageHelper包冲突解决
⏱️ @ 创作时间: 2024年03月15日

在这里插入图片描述

前言

在将项目由SpringBoot2.x升级为SpringBoot3.2.0时,对Mybatis-Plus及Pagehelper同时进行了升级,升级过程组出现了包冲突以及factoryBeanObjectType异常的情况,下面是一个总结!

1、SpringBoot3在整合Mybatis-Plus与PageHelper的同时会出现,包冲突问题

pagehelper-spring-boot-starter包中会引入mybatis-spring-boot-starter包,会与mybatis-plus-boot-starter出现冲突:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties$CoreConfiguration.applyTo(MybatisPlusProperties.java:356)

The following method did not exist:

    'void org.apache.ibatis.session.Configuration.setArgNameBasedConstructorAutoMapping(boolean)'

The calling method's class, com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties$CoreConfiguration, was loaded from the following location:

    jar:file:/D:/m2/com/baomidou/mybatis-plus-spring-boot-autoconfigure/3.5.4.1/mybatis-plus-spring-boot-autoconfigure-3.5.4.1.jar!/com/baomidou/mybatisplus/autoconfigure/MybatisPlusProperties$CoreConfiguration.class

The called method's class, org.apache.ibatis.session.Configuration, is available from the following locations:

    jar:file:/D:/m2/org/mybatis/mybatis/3.5.9/mybatis-3.5.9.jar!/org/apache/ibatis/session/Configuration.class

The called method's class hierarchy was loaded from the following locations:

    org.apache.ibatis.session.Configuration: file:/D:/m2/org/mybatis/mybatis/3.5.9/mybatis-3.5.9.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties$CoreConfiguration and org.apache.ibatis.session.Configuration

解决包冲突:
需要排除mybatis-spring-boot-starter

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis.spring.boot</groupId>
                    <artifactId>mybatis-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

2、factoryBeanObjectType错误

出现java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String异常信息

java.lang.IllegalArgumentException: Invalid value type for attribute 'factoryBeanObjectType': java.lang.String
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getTypeForFactoryBeanFromAttributes(FactoryBeanRegistrySupport.java:86)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:838)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:620)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:573)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:532)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:138)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:775)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:597)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:323)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331)
	at com.lhz.demo.DemoApplication.main(DemoApplication.java:10)

解决方案:
需要排除mybatis-plus-boot-startermybatis-spring,并且单独引入高版本的mybatis-spring

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.4.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis-spring</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>3.0.3</version>
        </dependency>

3、完整pom配置

<dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.4.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis.spring.boot</groupId>
                    <artifactId>mybatis-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.4.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis</groupId>
                    <artifactId>mybatis-spring</artifactId>
                </exclusion></exclusions>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>3.0.3</version>
        </dependency>

在这里插入图片描述

相关推荐

  1. SpringBoot整合MyBatis-Plus

    2024-03-15 17:54:01       40 阅读
  2. springBoot mybatis-plus整合

    2024-03-15 17:54:01       19 阅读
  3. springboot整合mybatis-plus

    2024-03-15 17:54:01       13 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-15 17:54:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-15 17:54:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-15 17:54:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-15 17:54:01       20 阅读

热门阅读

  1. Spring Boot写一个简单的PDF到Word的转换程序

    2024-03-15 17:54:01       19 阅读
  2. LinearLayout和RelativeLayout对比

    2024-03-15 17:54:01       22 阅读
  3. 利益相关者理论(stakeholder theory)

    2024-03-15 17:54:01       17 阅读
  4. 简单聊一下 Python asyncio

    2024-03-15 17:54:01       20 阅读
  5. 2085. 统计出现过一次的公共字符串

    2024-03-15 17:54:01       19 阅读
  6. MySQL--索引常见面试题详解

    2024-03-15 17:54:01       22 阅读
  7. Python中,如何检查一个变量是否存在?

    2024-03-15 17:54:01       19 阅读
  8. 【Android】源码中的单例模式

    2024-03-15 17:54:01       19 阅读
  9. 服务器通常会遭到哪些攻击手段?

    2024-03-15 17:54:01       21 阅读
  10. 无人机的航向角

    2024-03-15 17:54:01       20 阅读
  11. 计算机网络规划与设计 -- 设计基础

    2024-03-15 17:54:01       22 阅读
  12. 研究生预答辩全解析

    2024-03-15 17:54:01       24 阅读
  13. JVM 面试题——CMS和G1的区别

    2024-03-15 17:54:01       21 阅读