App下載

Mybatis-plus和pagehelper依賴產(chǎn)生沖突問(wèn)題的具體解決方案

猿友 2021-08-05 12:41:49 瀏覽數(shù) (7340)
反饋

在使用 Mybatis-plus 工具,同時(shí)又引入了 pagehelper 的依賴,結(jié)果導(dǎo)致了沖突問(wèn)題。那么該如何解決這個(gè)問(wèn)題?下面,將通過(guò)實(shí)例來(lái)為大家展示 Mybatis-plus 和 pagehelper 依賴沖突的解決方法。

簡(jiǎn)介

MyBatis-Plus(簡(jiǎn)稱 MP)是一個(gè) MyBatis 的增強(qiáng)工具,在 MyBatis 的基礎(chǔ)上只做增強(qiáng)不做改變,為簡(jiǎn)化開(kāi)發(fā)、提高效率而生。

啟動(dòng)即會(huì)自動(dòng)注入基本 CURD,性能基本無(wú)損耗,直接面向?qū)ο蟛僮?/p>

Mybati-plus本身自帶分頁(yè)功能,但是我個(gè)人一直是使用pagehelper進(jìn)行分頁(yè),所以在pom中添加了pagehelper依賴,但是運(yùn)行項(xiàng)目后發(fā)現(xiàn)jar包沖突,面對(duì)沖突我們應(yīng)該怎么解決它呢,看完如下內(nèi)容便可輕松解決

先看依賴

        <!-- mbatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.1.2</version>
        </dependency>
 
        <!--generator-->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.1.2</version>
 
        </dependency>
 
     
        <!-- pagehelper-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
         </dependency>

運(yùn)行項(xiàng)目

***************************
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.core.MybatisMapperAnnotationBuilder.getLanguageDriver(MybatisMapperAnnotationBuilder.java:369)
The following method did not exist:
com.baomidou.mybatisplus.core.MybatisConfiguration.getLanguageDriver(Ljava/lang/Class;)Lorg/apache/ibatis/scripting/LanguageDriver;
The method's class, com.baomidou.mybatisplus.core.MybatisConfiguration, is available from the following locations:
jar:file:/Applications/MrWang/Maven/privite_wang_repository/com/baomidou/mybatis-plus-core/3.1.2/mybatis-plus-core-3.1.2.jar!/com/baomidou/mybatisplus/core/MybatisConfiguration.class
It was loaded from the following location:
file:/Applications/MrWang/Maven/privite_wang_repository/com/baomidou/mybatis-plus-core/3.1.2/mybatis-plus-core-3.1.2.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of com.baomidou.mybatisplus.core.MybatisConfiguration
Disconnected from the target VM, address: '127.0.0.1:55790', transport: 'socket'
Process finished with exit code 0

糾正應(yīng)用程序的類路徑,使其包含com.baomidou.mybatisplus.core.MybatisConfiguration的單一兼容版本

2021041409374017

標(biāo)紅的部分是灰色的,看后面括號(hào)中的意思 (為沖突而生 ),這個(gè)包跟上面的包是一樣的,上面是亮的,下面是灰色的,說(shuō)明系統(tǒng)用了上面的jar包,導(dǎo)致下面jar包提示沖突,但為什么不用下面的,自己私下花點(diǎn)時(shí)間 研究一下,當(dāng)然我們的目的不是解決這個(gè)沖突,因?yàn)檫@個(gè)被系統(tǒng)檢測(cè)出來(lái)了,系統(tǒng)自動(dòng)停用了一個(gè),我們要解決系統(tǒng)檢測(cè)不出來(lái)的沖突

引入 MyBatis-Plus 之后請(qǐng)不要再次引入 MyBatis 以及 MyBatis-Spring,以避免因版本差異導(dǎo)致的問(wèn)題。(Mybatis-plus官網(wǎng)原話)

pagehelper依賴包中由上圖得知,也是包含了MyBatis 以及 MyBatis-Spring,而MyBatis-Spring依賴沖突,系統(tǒng)自動(dòng)用了Mybatis-plus中的MyBatis-Spring,所以我們只需要把pagehelper中的mybatis依賴刪除即可,具體操作如下

在version 下面添加 exclusions依賴(排除)

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

重啟項(xiàng)目并測(cè)試

postman測(cè)試結(jié)果

2021041409374018

 問(wèn)題完美解決了

到此這篇關(guān)于使用Mybatis-plus工具和引入pagehelper依賴而產(chǎn)生的沖突問(wèn)題以及具體解決方法的文章就介紹到這了,想要了解更多相關(guān)Mybatis-plus或者pagehelper依賴的其他詳細(xì)內(nèi)容,請(qǐng)搜索W3Cschool以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持!

0 人點(diǎn)贊