欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

SpringBoot3 集成 Mybatis-Plus 和 PageHelper 软件包冲突解决

最编程 2024-03-15 17:33:30
...
???? @ 作者: 一恍过去
???? @ 主页: https://blog.****.net/zhuocailing3390
???? @ 社区: Java技术栈交流
???? @ 主题: SpringBoot3整合Mybatis-Plus与PageHelper包冲突解决
⏱️ @ 创作时间: 2024年03月15日

在这里插入图片描述

目录

    • 前言
    • 1、SpringBoot3在整合Mybatis-Plus与PageHelper的同时会出现,包冲突问题
    • 2、factoryBeanObjectType错误
    • 3、完整pom配置

前言

在将项目由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>

在这里插入图片描述