SpringBoot项目报错汇总

发布于:2025-06-11 ⋅ 阅读:(44) ⋅ 点赞:(0)

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 文件或者接口注解里定义一次。

二、解决办法

image-20250610104133642

image-20250610104247333

存在重复定义,移除一个重复的即可。如上图所示,可以移除注解定义 @Select("SELECT * FROM short_link WHERE short_code = #{shortCode}")

成功解决🤗🤗🤗

SLF4J: Class path contains multiple SLF4J bindings.

一、问题描述

image-20250610162103860

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 绑定,从而触发了警告。

二、解决办法

成功解决🤗🤗🤗

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 接口。

二、解决办法

出现该问题的几种情形:

  1. 对应的 Mapper 目录写错了;
  2. 少了配置文件;
  3. 在应用入口类:XxxApplication.java中没有加入@MapperScan(basePackages = {""})注解;
  4. 注解方式不对,可使用@Mapper注解。

博主属于第三种情况,所以在启动类加上了MapperScan注解。

image-20250610174421785

成功解决🤗🤗🤗


网站公告

今日签到

点亮在社区的每一天
去签到