App下載

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

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

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

簡介

MyBatis-Plus(簡稱 MP)是一個 MyBatis 的增強工具,在 MyBatis 的基礎上只做增強不做改變,為簡化開發(fā)、提高效率而生。

啟動即會自動注入基本 CURD,性能基本無損耗,直接面向?qū)ο蟛僮?/p>

Mybati-plus本身自帶分頁功能,但是我個人一直是使用pagehelper進行分頁,所以在pom中添加了pagehelper依賴,但是運行項目后發(fā)現(xiàn)jar包沖突,面對沖突我們應該怎么解決它呢,看完如下內(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>

運行項目

***************************
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

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

2021041409374017

標紅的部分是灰色的,看后面括號中的意思 (為沖突而生 ),這個包跟上面的包是一樣的,上面是亮的,下面是灰色的,說明系統(tǒng)用了上面的jar包,導致下面jar包提示沖突,但為什么不用下面的,自己私下花點時間 研究一下,當然我們的目的不是解決這個沖突,因為這個被系統(tǒng)檢測出來了,系統(tǒng)自動停用了一個,我們要解決系統(tǒng)檢測不出來的沖突

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

pagehelper依賴包中由上圖得知,也是包含了MyBatis 以及 MyBatis-Spring,而MyBatis-Spring依賴沖突,系統(tǒ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>

重啟項目并測試

postman測試結(jié)果

2021041409374018

 問題完美解決了

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

0 人點贊