解决Mybatis-plus和pagehelper依赖冲突
简介
(简称 MP)是一个 的增强工具,在 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 methods 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测试结果
问题完美解决了