springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
一、前言:
使用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.的更多相关文章
- 【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 ...
- 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案
搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...
- Consider defining a bean of type `xxx` in your configuration问题解决
在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************** ...
- IntelliJ IDEA 2017版 spring-boot 报错Consider defining a bean of type 'xxx' in your configuration问题解决方案
问题分析: 通过问题的英文可知,这个错误是service的bean注入失败,那么为什么会产生这个问题呢? 主要是框架的Application产生的,所以我们建立项目的时候,要保证项目中的类跟Appli ...
- springboot Consider defining a bean of type 'xxx' in your configuration
这个错误是service的bean注入失败,主要是Application位置不对,要保证项目中的类在Application启动服务器类的下一级目录,如图:
- spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案
经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动 ...
- 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 ...
- 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 创建 ...
- Springboot 之 启动报错-Cannot determine embedded database driver class for database type NONE
Springboot 之 启动报错-数据库 springboot项目在启动时,报如下错误: Error starting ApplicationContext. To display the auto ...
随机推荐
- npm install报错Unhandled rejection RangeError: Maximum call stack size exceededill install
故障 在使用npm install下载依赖的时候报错Unhandled rejection RangeError: Maximum call stack size exceededill instal ...
- css3中linear-gradient()的使用
用线性渐变创建图像. 如果想创建以对角线方式渐变的图像,可以使用 to top left 这样的多关键字方式来实现. 示例代码: linear-gradient(#fff, #333); linear ...
- keepalived工作原理和配置文件说明
keepalived是什么 keepalived是集群管理中保证集群高可用的一个服务软件,其功能类似于heartbeat,用来防止单点故障. keepalived工作原理 keepalived是以VR ...
- 多重背包--java
多重背包 有N种物品和一个容量为V的背包.第i种物品最多有n[i]件可用,每件费用是c[i],价值 是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大母函数的思想也 ...
- mysql安装5.7.20版本
安 装 命 令:mysqld install 初始化命令:mysqld –initialize 参考这个链接 http://blog.csdn.net/wlc57627451/article/deta ...
- Linux命令第三篇
作业三: 以操作文件的方式,新建一个用户alex echo "alex:x:1200:1200::/home/alex/:/bin/bash" >> /etc/pass ...
- What is the NETStandard.Library metapackage?
In my last post, I took a quick look at the Microsoft.AspNetCore meta package. One of the libraries ...
- Java名称字符串进行星号处理
/** * 对字符串处理:将指定位置到指定位置的字符以星号代替 * * @param content * 传入的字符串 * @param begin * 开始位置 * @param end * 结束位 ...
- jpa-规范
看图
- Spark2.2(三十九):如何根据appName监控spark任务,当任务不存在则启动(任务存在当超过多久没有活动状态则kill,等待下次启动)
业务需求 实现一个根据spark任务的appName来监控任务是否存在,及任务是否卡死的监控. 1)给定一个appName,根据appName从yarn application -list中验证任务是 ...