【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 ...
随机推荐
- usb3.0驱动
usb3.0驱动下载地址 华硕注入usb3.0驱动工具下载地址 https://dlsvr04.asus.com/pub/ASUS/misc/utils/ASUS_EZInstaller_V10306 ...
- Linux菜鸟起飞之路【三】Linux常用命令
一.Linux命令的基本格式 命令 [选项] [参数] a)命令:就是告诉操作系统要做什么 b)选项:说明命令的运行方式,有的会改变命令的功能,选项通常以“-”开始 c)参数:说明命令的操作对象,如文 ...
- hdu 5437
Alisha’s Party Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- express中间件的next()方法
next()方法出现在express框架中的中间件部分,由于node异步的原因,我们需要提供一种机制,当当前中间件工作完成之后,通知下一个中间件执行,因此一个基本的中间件应该是这种形式 var mid ...
- Python基础数据类型之集合
Python基础数据类型之集合 集合(set)是Python基本数据类型之一,它具有天生的去重能力,即集合中的元素不能重复.集合也是无序的,且集合中的元素必须是不可变类型. 一.如何创建一个集合 #1 ...
- Mac 生成public_key
1.首先查看是否已经生成过public_key 打开终端查看是否已经存在SSH密钥:cd ~/.ssh 输出:No such file or directory表示没有 2.生成public_key ...
- HDU 2435 There is a war
There is a war Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...
- HDU1007 TLE代码和AC代码对比
这题卡了一天,上午开始看算法导论,然后实现了,一开始是wa,后来TLE,由于我开始的实现方式比较笨,而且在递归调用的时候很是混乱,用了好多数组.导致我的代码不断的出问题.具体是算法导论33-4. 后来 ...
- tomcat的安装和优化二
JAVA应用服务器weblogicwebsphere tomcat resin(百度,去哪网,搜狗,人人,互动百科)jboss resin官网:www.caucho.com jvm的调优: 1 JAM ...
- jQuery中文文档
http://www.jquery123.com/ http://www.shifone.cc/