一、前言:

使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图:

Description:

Field userEntityMapper in com.xxx.xxx.service.UserService required a bean of type 'com.xxx.xxx.dao.UserEntityMapper' that could not be found.

Action:

Consider defining a bean of type 'com.xxx.xxx.dao.UserEntityMapper' in your configuration.

二、解决方式:

1.检查自己写的注解是否错了,并没有。

2.在网上查找解决方式:如下所示:

步骤一:

  在springboot的配置文件添加,mybatis的配置如下所示:

mybatis:
typeAliasesPackage: com.xxx.xxx.dao.entity
mapperLocations: classpath:mapper/*.xml

步骤二:

  ①将接口与对应的实现类放在与application启动类的同一个目录或者他的子目录下,这样注解可以被扫描到,这是最省事的办法。(没测试)
  ②或者在启动类上加上@MapperScan或者@ComponentScan注解,手动指定application类要扫描哪些包下的注解,如下所示:

@SpringBootApplication
@ComponentScan(basePackages = {"com.xxx.xxx.dao"})

  ③或者在接口上添加@Mapper注解。

@Mapper
public interface UserMapper {
}

ps:之所以没有找到对应的Bean是因为,@SpringBootApplication没有扫描到。

参考:关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.的更多相关文章

  1. 【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:50 ...

  2. 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

    搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...

  3. Consider defining a bean of type `xxx` in your configuration问题解决

    在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************** ...

  4. IntelliJ IDEA 2017版 spring-boot 报错Consider defining a bean of type 'xxx' in your configuration问题解决方案

    问题分析: 通过问题的英文可知,这个错误是service的bean注入失败,那么为什么会产生这个问题呢? 主要是框架的Application产生的,所以我们建立项目的时候,要保证项目中的类跟Appli ...

  5. springboot Consider defining a bean of type 'xxx' in your configuration

    这个错误是service的bean注入失败,主要是Application位置不对,要保证项目中的类在Application启动服务器类的下一级目录,如图:

  6. spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案

    经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动 ...

  7. springboot测试启动报错java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

    springboot测试启动报错: java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you ne ...

  8. springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde

    springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde 创建 ...

  9. Springboot 之 启动报错-Cannot determine embedded database driver class for database type NONE

    Springboot 之 启动报错-数据库 springboot项目在启动时,报如下错误: Error starting ApplicationContext. To display the auto ...

随机推荐

  1. [COCI2015]COCI

    [COCI2015]COCI 题目大意: 有\(n(n\le5\times10^5)\)个人比赛,比赛总共进行\(3\)轮,每一轮得分为\([0,650]\)内的整数.现在已经得知每个人前两轮的成绩. ...

  2. [CC-BLREDSET]Black and Red vertices of Tree

    [CC-BLREDSET]Black and Red vertices of Tree 题目大意: 有一棵\(n(\sum n\le10^6)\)个结点的树,每个结点有一种颜色(红色.黑色.白色).删 ...

  3. bzoj3376/poj1988[Usaco2004 Open]Cube Stacking 方块游戏 — 带权并查集

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3376 题目大意: 编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方 ...

  4. Scrapy 使用CrawlSpider整站抓取文章内容实现

    刚接触Scrapy框架,不是很熟悉,之前用webdriver+selenium实现过头条的抓取,但是感觉对于整站抓取,之前的这种用无GUI的浏览器方式,效率不够高,所以尝试用CrawlSpider来实 ...

  5. C语言基础二(敲打键盘、寻找资料)

    看过很多资料的人,估计发觉了什么,我上篇的基础一其中一个最致命的错误,没有加return 0; 为什么不加,说真的,我留个坑,所以跳跃性的直接说到函数是如何运用的. 上章说到main就是主入口,根据m ...

  6. Tornado-cookie

    cookie 服务端在客户端的中写一个字符串,下一次客户端再访问时只要携带该字符串,就认为其是合法用户. tornado中的cookie有两种,一种是未加密的,一种是加密的,并且可以配置生效域名.路径 ...

  7. .ipynb格式文件

    ipynb,即ipython notebook,需要用ipython notebook打开,IPython Notebook是web based IPython封装,但是可以展现富文本,使得整个工作可 ...

  8. 使用mkbootfs制作ramdisk根文件系统

    span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }.CodeMirror ...

  9. arcgis 获得工具箱工具的个数

    import arcgisscripting import string; gp = arcgisscripting.create(9.3); ##多少个工具箱 toolboxes = gp.list ...

  10. CSS魔法堂:display:none与visibility:hidden的恩怨情仇

    前言  还记得面试时被问起"请说说display:none和visibility:hidden的区别"吗?是不是回答完display:none不占用原来的位置,而visibilit ...