一、前言:

使用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. Struts2网页面传值两种方式

    第一种方式: /** 列表 */ public String list() throws Exception { List<Role> roleList = roleService.fin ...

  2. 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习6

    #include <iostream>using namespace std;struct CandyBar{ char kind[20]; float weight; int calor ...

  3. Node回调&事件

    Node回调&事件 Node.js 异步编程的直接体现就是回调,异步编程依托于回调来实现 简介 回调函数在任务完成后会被调用,node的所有API都支持回调函数,回调函数提高了Node的性能, ...

  4. C#常用IO流与读写文件 (转)

    源自https://www.cnblogs.com/liyangLife/p/4797583.html 谢谢 1.文件系统 (1)文件系统类的介绍 文件操作类大都在System.IO命名空间里.Fil ...

  5. sqlmap简单使用

    就以实验吧上那个简单的sql注入题为例吧,不过那道题确实经典,把sqlmap的整个使用过程都展现了一遍,先奉上那道题的地址:http://ctf5.shiyanbar.com/web/index_3. ...

  6. hihocoder1696 折线中点(几何)

    https://hihocoder.com/problemset/problem/1696 求折线中点,一开始想成先求横坐标中点了,肯定是错的. 一定要从线段长度求中点,然后中点公式推了好久.. #i ...

  7. Asp.NET WebApi+Redis实现单用户登录实战演练

    一.课程介绍 本次分享课程属于<C#高级编程实战技能开发宝典课程系列>中的一部分,阿笨后续会计划将实际项目中的一些比较实用的关于C#高级编程的技巧分享出来给大家进行学习,不断的收集.整理和 ...

  8. 纯 CSS 实现高度与宽度成比例的效果

    http://zihua.li/2013/12/keep-height-relevant-to-width-using-css/

  9. ARCGIS做好的模型工具,已经设置为相对路径,拷贝后工具显示叉叉不可用的原因

    .用户遇到此问题的场景: 用ModelBuilder构建了一系列的模型,其中有些模型很复杂,就把部分抽离出来,然后再整合到一起,我发现把整个模型工具箱拷贝到其他电脑上,这些复杂模型(里面除了系统自带的 ...

  10. 微信小程序生成指定页面小程序码海报图片分享思路总结

    本博客主要说下思路,具体代码不贴 1.考虑到组件复用,所以我把它做成一个自定义的组件 <my-poster id="getPoster" avater="{{ima ...