news 2026/7/22 7:16:58

SpringBoot启动失败--扫描不到Bean

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
SpringBoot启动失败--扫描不到Bean

报错日志

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-12-19 10:29:35.762 ERROR 580 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

*************************** APPLICATION FAILED TO START ***************************

Description: Field userMapper in nuc.edu.testspring.Service.Impl.UserServiceImpl required a bean of type 'nuc.edu.testspring.mapper.UserMapper' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true)

Action: Consider defining a bean of type 'nuc.edu.testspring.mapper.UserMapper' in your configuration.

进程已结束,退出代码为 1

解决方案

步骤 1:修复依赖兼容性问题(避免隐性报错)

你的mybatis-spring-boot-starter版本是 3.0.0,而 Spring Boot 2.6.13 和该版本不兼容(3.0.0 要求 Spring Boot 2.7+),需调整版本:

pom

<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.2</version> <!-- 适配Spring Boot 2.6.x --> </dependency>
步骤 2: 给 Mapper 接口添加@Mapper注解

UserMapper接口上添加 MyBatis 的@Mapper注解,示例:

java

package nuc.edu.testspring.mapper; import nuc.edu.testspring.entity.User; import org.apache.ibatis.annotations.Mapper; // 关键注解 import java.util.List; @Mapper // 标记为MyBatis Mapper,让Spring扫描并创建Bean public interface UserMapper { // 你的Mapper方法(比如查询用户) User selectById(Long id); }
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/22 5:15:40

MCP服务器故障排查:7种常见问题快速解决方案

MCP服务器故障排查&#xff1a;7种常见问题快速解决方案 【免费下载链接】servers Model Context Protocol Servers 项目地址: https://gitcode.com/GitHub_Trending/se/servers 你是否在部署Model Context Protocol服务器时遇到过各种奇怪的问题&#xff1f;从路径访问…

作者头像 李华
网站建设 2026/7/21 18:38:03

从3小时到3分钟:用现代工具快速解决Python依赖地狱

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 构建一个交互式命令行工具&#xff0c;通过AI分析快速解决Python依赖问题。对于urllib3 v2与OpenSSL冲突&#xff1a;1) 自动识别环境配置 2) 分析依赖树 3) 提供一键修复方案 4) 生…

作者头像 李华
网站建设 2026/7/21 9:01:47

Proton-GE Wayland支持终极指南:一键启用原生Linux游戏体验

Proton-GE Wayland支持终极指南&#xff1a;一键启用原生Linux游戏体验 【免费下载链接】proton-ge-custom 项目地址: https://gitcode.com/gh_mirrors/pr/proton-ge-custom 想要在Linux系统上获得更流畅、更原生的游戏体验吗&#xff1f;Proton-GE的Wayland支持功能可…

作者头像 李华
网站建设 2026/7/21 15:49:39

5分钟搭建Git命令速查手册网页版

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 快速生成一个Git命令速查网页应用。要求&#xff1a;1)按功能分类&#xff08;基础、分支、远程等&#xff09;&#xff1b;2)支持关键词搜索&#xff1b;3)每个命令显示语法、参数…

作者头像 李华
网站建设 2026/7/22 4:12:35

AI如何用json.load简化Python数据解析

快速体验 打开 InsCode(快马)平台 https://www.inscode.net输入框内输入如下内容&#xff1a; 创建一个Python脚本&#xff0c;使用json.load从文件中读取JSON数据并解析为Python对象。要求包含错误处理逻辑&#xff0c;当JSON格式不正确时能给出友好提示。同时展示如何访问解…

作者头像 李华
网站建设 2026/7/21 9:35:41

终极指南:提升Java系统监控项目开发效率的5个核心策略

终极指南&#xff1a;提升Java系统监控项目开发效率的5个核心策略 【免费下载链接】oshi Native Operating System and Hardware Information 项目地址: https://gitcode.com/gh_mirrors/os/oshi 在当今快速迭代的开发环境中&#xff0c;Java系统监控项目的代码质量和开…

作者头像 李华