簡介
MyBatis-Plus(簡稱 MP)是一個 MyBatis 的增強工具,在 MyBatis 的基礎上只做增強不做改變,為簡化開發、提高效率而生。
啟動即會自動注入基本 CURD,性能基本無損耗,直接面向對象操作
Mybati-plus本身自帶分頁功能,但是我個人一直是使用pagehelper進行分頁,所以在pom中添加了pagehelper依賴,但是運行項目后發現jar包沖突,面對沖突我們應該怎么解決它呢,看完如下內容便可輕松解決
先看依賴
<!-- 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的單一兼容版本
標紅的部分是灰色的,看后面括號中的意思 (為沖突而生 ),這個包跟上面的包是一樣的,上面是亮的,下面是灰色的,說明系統用了上面的jar包,導致下面jar包提示沖突,但為什么不用下面的,自己私下花點時間 研究一下,當然我們的目的不是解決這個沖突,因為這個被系統檢測出來了,系統自動停用了一個,我們要解決系統檢測不出來的沖突
引入 MyBatis-Plus
之后請不要再次引入 MyBatis
以及 MyBatis-Spring
,以避免因版本差異導致的問題。(Mybatis-plus官網原話)
pagehelper依賴包中由上圖得知,也是包含了MyBatis
以及 MyBatis-Spring,而MyBatis-Spring依賴沖突,系統自動用了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測試結果
問題完美解決了
到此這篇關于解決Mybatis-plus和pagehelper依賴沖突的方法示例的文章就介紹到這了,更多相關Mybatis-plus和pagehelper依賴沖突內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/qq_42227281/article/details/95479858