一、前言:

使用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. BZOJ5103 : [POI2018]Róznorodno

    从上到下枚举上下底边,那么涉及两行的添加和删除. 首先预处理出对于每一列,每个位置添加和删除时,是否会对往下$k$个里出现这个颜色造成影响. 然后对于每种颜色维护一个长度为$m$的bitset,表示哪 ...

  2. 高速公路 [HAOI2012] [线段树]

    Description Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站. Y901高速公路是一条由N-1段路以及N个 ...

  3. yii2 配合bootstrap添加按钮

    新增一个按钮 1.bootstrap 官网:http://getbootstrap.com/ 2.bootstrap 中文官网:http://v3.bootcss.com/ 在视图文件中: <? ...

  4. 利用Ajax和JSON实现关于查找省市名称的二级联动功能

    功能实现的思路:我们经常碰见网上购物时候填写收件地址会用到这个查找省市县的三级联动查找功能,我们可以利用Ajax和JSON技术模拟这个功能,说白了同样是使用Ajax的局部数据更新功能这个特性.因为省市 ...

  5. SuperWebSocket与Cocos2dx通信时执行不了命令的问题

    要修改WebSocketSession.cs 中的方法 string IWebSocketSession.GetAvailableSubProtocol(string protocol) { if ( ...

  6. 第三届“百越杯”福建省高校网络空间安全大赛writeup--Do you know upload?

    一打开网址,可以看出应该是文件上传漏洞,查看源码,也有可能是文件包含 上传个图片,成功,然后上传一句话木马 通过bp进行上传绕过 , 开始菜刀连接http://e00b6eca3c9c4e14a31c ...

  7. iOS开发中的富文本

    1. 改变指定字符的颜色 NSString * text = [NSString stringWithFormat:@"%@米",distance]; NSMutableAttri ...

  8. RS485 VS 20mA 电流环

    RS485采用差分信号负逻辑,+2V-+6V表示“0”,- 6V-- 2V表示“1”.RS485有两线制和四线制两种接线,四线制只能实现点对点的通信方式,现很少采用,现在多采用的是两线制接线方式,这种 ...

  9. Java 将 List 里面的内容写入桌面的 txt 文档

    文件内容: /** * 将 list 写入文件中 */ import java.io.BufferedWriter; import java.io.File; import java.io.FileW ...

  10. Spring Boot中使用Swagger2自动构建API文档

    由于Spring Boot能够快速开发.便捷部署等特性,相信有很大一部分Spring Boot的用户会用来构建RESTful API.而我们构建RESTful API的目的通常都是由于多终端的原因,这 ...