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

本文描述了在将项目从SpringBoot2.x升级到3.2.0时,遇到的Mybatis-Plus与PageHelper整合时的包冲突问题,包括如何处理factoryBeanObjectType异常,以及完整的POM配置调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

😊 @ 作者: 一恍过去
🎊 @ 社区: 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>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一恍过去

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值