【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration. 【Mapper类不能被找到】@Mapper 和@MapperScan注解的区别
启动报错:
2018-05-16 17:22:58.161 ERROR 4080 --- Disconnected from the target VM, address: '127.0.0.1:50529', transport: 'socket'
[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : ***************************
APPLICATION FAILED TO START
*************************** Description: Field huaYangAreaMapper in com.sxd.swapping.service.impl.HuaYangServiceImpl required a bean of type 'com.sxd.swapping.dao.mybatis.HuaYangAreaMapper' that could not be found. Action: Consider defining a bean of type 'com.sxd.swapping.dao.mybatis.HuaYangAreaMapper' in your configuration.
解决方案:
根据错误提示
Mybatis的 Mapper类不能被找到,所以需要通过注解标明这个类可以给spring 管理并且给其他类调用的。
下面有两种方式提供:
方式1:使用@Mapper注解标注在Mapper类上
@Mapper
public interface HuaYangAreaMapper { @Select("SELECT * FROM hua_yang_area where uid = #{uid}")
@Results({
@Result(property = "areaName",column = "area_name",javaType = String.class),
@Result(property = "areaPerson",column = "area_person",javaType = Long.class),
@Result(property = "createId",column = "create_id",javaType = String.class)
})
HuaYangArea findOne(String uid); }
方式2:使用@MapperScan("mapper类所在包位置")
@SpringBootApplication
@MapperScan("com.sxd.swapping.dao.mybatis")
public class SwappingApplication { public static void main(String[] args) {
SpringApplication.run(SwappingApplication.class, args);
}
}
如果有多个包需要被扫描到,可以传入字符串数组
@MapperScan({"com.sxd.swapping.dao.mybatis","com.sxd.swapping.dao.mapper"})
上面这两种方式都可以使用。
====================================
至于@Mapper 和@MapperScan注解的区别,一个只需要在启动类配置一次,一个是需要在每个mapper上进行配置
【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration. 【Mapper类不能被找到】@Mapper 和@MapperScan注解的区别的更多相关文章
- Spring boot&Mybatis 启动报错 Failed to auto-configure a DataSource
*************************** APPLICATION FAILED TO START *************************** Description: Fai ...
- springboot 启动报错Consider defining a bean of type 'com.example.springbootdruid.mapper.UserMapper' in your configurati
一.问题 springboot项目启动时报错: Field userMapper in com.example.springbootdruid.service.impl.UserServiceImpl ...
- Sping Cloud项目启动报A component required a bean of type 'com.tianyan.bbc.dao.SecurityUserBaseMapper' that could not be found.
项目构建正常,启动和Debug报以下错误: Error starting ApplicationContext. To display the conditions report re-run you ...
- 创建spring boot项目启动报错遇到的问题
1.Spring boot,Mybatis 启动报错 Failed to auto-configure a DataSource *************************** APPLICA ...
- 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add
报错如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.i ...
- spring cloud gateway网关启动报错:No qualifying bean of type 'org.springframework.web.reactive.DispatcherHandler'
网关配置好后启动报错如下: org.springframework.context.ApplicationContextException: Unable to start web server; n ...
- IntelliJ IDEA 2017版 spring-boot 报错Consider defining a bean of type 'xxx' in your configuration问题解决方案
问题分析: 通过问题的英文可知,这个错误是service的bean注入失败,那么为什么会产生这个问题呢? 主要是框架的Application产生的,所以我们建立项目的时候,要保证项目中的类跟Appli ...
- spring boot项目启动报错
在eclipse中运行没有任何问题,项目挪到idea之后就报错 Unable to start EmbeddedWebApplicationContext due to miss EmbeddedSe ...
- spring 整合Mybatis 《报错集合,总结更新》
错误:java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldExcepti ...
随机推荐
- PAT 乙级 1041
题目 题目地址:PAT 乙级 1041 题解 这道题学到的东西恰好和1037中学到的东西相互补充,总结如下: 在之前的博文中我曾提到过——“结构体在函数内部对数据的操作不能赋给主函数中的实参,函数内部 ...
- [LUOGU] 1717 钓鱼
题目描述 话说发源于小朋友精心设计的游戏被电脑组的童鞋们藐杀之后非常不爽,为了表示安慰和鼓励,VIP999决定请他吃一次"年年大丰收",为了表示诚意,他还决定亲自去钓鱼,但是,因为 ...
- python 删除大表数据
#!/usr/bin/env python # encoding: utf-8 #@author: 东哥加油! #@file: del_tb_bigtable_statistic.py #@time: ...
- windows 使用git上传代码至github
1. 首先创建github账户 2. 创建github项目 3. windows安装git工具 ·下载地址:https://git-for-windows.github.io/ ,下载直接安装即可, ...
- MySQL开启日志跟踪
在开发过程中有时候会遇到sql相关的问题,但是有时候代码中不会直接看到真实的sql,想要看到mysql中实际执行的是什么sql,可以通过开启日志跟踪方式查看. 1 开启日志跟踪 SET GLOBAL ...
- cvs 文件无法上传debug
当时文件始终上传不成功时(一般先update后commit): cvs update filename report:move away filename ,it is in the way cvs ...
- 分析laravel的核心日志类
首先是容器 log对应的是application这个容器 首先我们查看如何获取这个日志类,我们来到\storage\app.php中找到application这个容器,点进去, 我们来到了 点击这个跳 ...
- 《linux设备驱动开发详解》笔记——11内存与IO访问
内存访问与映射是linux驱动常见操作,操作硬件时离不开内存的映射,本章比较重要. 11.1 CPU与内存.I/O 目前的嵌入式处理器,都不提供专门的I/O空间,而仅存在内存空间:各种外设寄存器都直接 ...
- 快照、克隆,xshell优化,Linux历史
目录 一.虚拟拍照功能 二.虚拟机克隆功能 三.Xshell的优化 四.介绍Linux历史 一.虚拟拍照功能 1.拍摄快照 关机状态拍照 关机命令:shutdown -h now 或者 init 0 ...
- C++类指针初始化
上面的代码会打印“A”. C++ 类指针定义的时候没有初始化的时候,居然可以安全的调用类内部的成员函数而不出错. 在网上查了一下: 初始化为NULL的类指针可以安全的调用不涉及类成员变量的类成员函 ...