【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 ...
随机推荐
- Luogu P2664 树上游戏 dfs+树上统计
题目: P2664 树上游戏 分析: 本来是练习点分治的时候看到了这道题.无意中发现题解中有一种方法可以O(N)解决这道题,就去膜拜了一下. 这个方法是,假如对于某一种颜色,将所有这种颜色的点全部删去 ...
- 使用VS2015编写驱动时出现的部分错误以及解决方法
前几日在github上下载了一个Windows驱动的demo,原本想着直接下载下来打开解决方案就可以用,没想到一编译,出现了奇奇怪怪的Error,部分Error网上也没什么好的解决办法,对我这个从未深 ...
- Redis 数据类型分析 字符串 哈希 列表 集合 有序集合 优缺点 分析 注意事项 存储结构
一.提高Redis使用性能秘诀 KEY尽量少的原则,能放在1个KEY的就放入1个KEY,KEY开销很大尽量减少与Redis发生的交互次数,能批量的就批量,能事务.管道的就事务.管道从业务架构分析确定使 ...
- 高性能MySQL(第三版)
一.MySQL架构与历史 1.2.2 锁粒度 表锁:写锁的优先级高于读锁:写锁的请求可以插入到读锁的前面,但读锁的请求却不能插入到写锁的前面: 行级锁:行级锁只在存储引擎层实现,在服务器层没有实现: ...
- luogu3698 [CQOI2017]小Q的棋盘
最长链是根节点到深度最深的结点的路径. 显然,要么直接走最长链,要么兜兜转转几个圈圈再走最长链,而最长链以外的结点因为要"兜圈",所以要经过两次. #include <ios ...
- Etree方式解析xml知识积累
movies.xml: <collection shelf="New Arrivals"> <movie title="Enemy Behind&quo ...
- Python内置函数5
Python内置函数5 1.format参考前面字符串方法中的format 2.frozenset([iterable]) iterable -- 可迭代的对象,比如列表.字典.元组等等 返回一个冻结 ...
- 图论trainning-part-1 A. 最短路
A. 最短路 Time Limit: 1000ms Memory Limit: 32768KB 64-bit integer IO format: %I64d Java class name ...
- 奇奇怪怪的冒泡排序 TOJ 2014: Scramble Sort
粘贴两个特别简单的冒泡排序 2014: Scramble Sort Description In this problem you will be given a series of lists co ...
- POJ-2187 Beauty Contest,旋转卡壳求解平面最远点对!
凸包(旋转卡壳) 大概理解了凸包A了两道模板题之后在去吃饭的路上想了想什么叫旋转卡壳呢?回来无聊就搜了一下,结果发现其范围真广. 凸包: 凸包就是给定平面图上的一些点集(二维图包),然后求点集组成的 ...