直接原因
以下兩個依賴會沖突,有了 mybatis-plus-boot-starter
,就不需要 spring 自己的 mybatis-spring-boot-starter
了。
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<!-- mybatis-plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
直接刪除 mybatis-spring-boot-starter
的引用就OK。
沒有找到 mybatis-spring-boot-starter
的依賴?
有趣的問題是,pom.xml 中沒有直接找到 mybatis-spring-boot-starter
的依賴,那么,很有可能是其它項目依賴了 mybatis-spring-boot-starter
,把這個依賴帶了進來。
使用 mvn denpendecy:tree
就可以分析出來,是誰依賴了 mybatis-spring-boot-starter
。
比如,我這里的情況就是,另一個項目依賴了 mybatis-spring-boot-starter
。
怎么解?
使用 exclusion 排除掉就可以啦。
如果有多個包依賴了 mybatis-spring-boot-starter
,都需要排除。
<dependency>
<groupId>com.xxx.xxx</groupId>
<artifactId>xxx-open-api</artifactId>
<exclusions>
<exclusion>
<artifactId>mybatis-spring-boot-starter</artifactId>
<groupId>org.mybatis.spring.boot</groupId>
</exclusion>
</exclusions>
</dependency>
如果是多工程的項目,使用 mvn dependency:tree
出現錯誤,可以參考這個:
[筆記] 多模塊 maven 工程中,mvn dependency:tree 分析,jar 包找不到的問題處理。
參考鏈接: