SpringBoot项目报错汇总
文章目录
- mapper [XXX] is ignored, because it exists, maybe from xml file
- 一、问题描述
- 二、解决办法
- SLF4J: Class path contains multiple SLF4J bindings.
- 一、问题描述
- 二、解决办法
- No MyBatis mapper was found in [XXX] package. Please check your configuration.
- 一、问题描述
- 二、解决办法
mapper [XXX] is ignored, because it exists, maybe from xml file
一、问题描述
mapper[com.github.paicoding.forum.service.shortlink.repository.mapper.ShortLinkMapper.getByShortCode] is ignored, because it exists, maybe from xml file
分析:根据报错信息可知 MyBatis 检测到 ShortLinkMapper
接口里的 getByShortCode
方法存在重复定义。在 MyBatis 里,若 XML 文件和接口方法都对同一个方法进行了定义,就会出现重复定义的问题。需要保证 ShortLinkMapper
接口中的 getByShortCode
方法仅在 XML 文件或者接口注解里定义一次。
二、解决办法
存在重复定义,移除一个重复的即可。如上图所示,可以移除注解定义 @Select("SELECT * FROM short_link WHERE short_code = #{shortCode}")
。
成功解决🤗🤗🤗
SLF4J: Class path contains multiple SLF4J bindings.
一、问题描述
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/ch/qos/logback/logback-classic/1.2.11/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/Administrator/.m2/repository/org/slf4j/slf4j-simple/1.7.36/slf4j-simple-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
分析:警告信息表明项目的类路径下存在多个 SLF4J 绑定实现,这可能会导致日志输出出现问题。在项目里,logback-classic 和 slf4j-simple 都提供了 SLF4J 绑定,从而触发了警告。
二、解决办法
-
下载「Maven Helper」插件。 https://plugins.jetbrains.com/plugin/7179-maven-helper
-
在 pom.xml 下面点开 「Dependency Analyzer」。
-
用插件过滤冲突,我这里是 slf4j-simple。
-
重新刷新依赖。
成功解决🤗🤗🤗
No MyBatis mapper was found in [XXX] package. Please check your configuration.
一、问题描述
No MyBatis mapper was found in '[com.github.paicoding.forum.web]' package. Please check your configuration.
分析:报错表明在 com.github.paicoding.forum.web 包下没有找到 MyBatis 的 Mapper 接口,MyBatis 扫描器未发现对应的 Mapper 接口。
二、解决办法
出现该问题的几种情形:
- 对应的 Mapper 目录写错了;
- 少了配置文件;
- 在应用入口类:
XxxApplication.java
中没有加入@MapperScan(basePackages = {""})
注解; - 注解方式不对,可使用
@Mapper
注解。
博主属于第三种情况,所以在启动类加上了MapperScan
注解。
成功解决🤗🤗🤗