关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案
搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考
Description: Field helloService in com.example.demo.service.TestController required a bean of type 'com.example.service.HelloService' that could not be found. Action: Consider defining a bean of type 'XXX' in your configuration.
根据英文的提示是在配置中找不到一个指定自动注入类型的bean,经过多方排查得出结论:
正常情况下加上@Component注解的类会自动被Spring扫描到生成Bean注册到spring容器中,既然他说没找到,也就是该注解被没有被spring识别,问题的核心关键就在application类的注解SpringBootApplication上
这个注解其实相当于下面这一堆注解的效果,其中一个注解就是@Component,在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动注册为Bean的@Service@Controller和@ Repository
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters={@Filter(type=CUSTOM, classes={TypeExcludeFilter.class}), @Filter(type=CUSTOM, classes={AutoConfigurationExcludeFilter.class})})
@Target(value={TYPE})
@Retention(value=RUNTIME)
@Documented
@Inherited
至此,得出两种解决办法:
1 .将接口与对应的实现类放在与application启动类的同一个目录或者他的子目录下,这样注解可以被扫描到,这是最省事的办法
2 .在指定的application类上加上这么一行注解,手动指定application类要扫描哪些包下的注解,见下图
通过这两种方式,那个找不到指定Bean的错误就成功解决了
参考:http://blog.csdn.net/a532672728/article/details/77702772
关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案的更多相关文章
- IntelliJ IDEA 2017版 spring-boot 报错Consider defining a bean of type 'xxx' in your configuration问题解决方案
问题分析: 通过问题的英文可知,这个错误是service的bean注入失败,那么为什么会产生这个问题呢? 主要是框架的Application产生的,所以我们建立项目的时候,要保证项目中的类跟Appli ...
- spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案
经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动 ...
- springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.
一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description: Field userEntityMapper in com.xxx. ...
- Consider defining a bean of type `xxx` in your configuration问题解决
在使用SpringBoot装配mybatis时出现了异常 *************************** APPLICATION FAILED TO START *************** ...
- springboot Consider defining a bean of type 'xxx' in your configuration
这个错误是service的bean注入失败,主要是Application位置不对,要保证项目中的类在Application启动服务器类的下一级目录,如图:
- Consider defining a bean of type 'package' in your configuration [Spring-Boot]
https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-config ...
- Spring Boot Autowirted注入找不到Bean对象解决方法
报错:Consider defining a bean of type 'xxxxxxxxxxxxx' in your configuration 1. 你应该在 ApplyApplication 启 ...
- Spring Boot自动配置源码解析(基于Spring Boot 2.0.2.RELEASE)
在Spring Boot官方介绍中,首一段话是这样的(如下图).我们可以大概了解到其所表达的含义:我们可以利用Spring Boot写很少的配置来创建一个非常方便的基于Spring整合第三方类库的单体 ...
- Spring boot 自动配置自定义配置文件
示例如下: 1. 新建 Maven 项目 properties 2. pom.xml <project xmlns="http://maven.apache.org/POM/4 ...
随机推荐
- 潭州课堂25班:Ph201805201 周五 (课堂笔记)
小三角: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- Putty 工具使用
如何使用Putty远程(SSH)管理Linux VPS Putty是一个免费的.Windows 32平台下的telnet.rlogin和ssh客户端,但是功能丝毫不逊色于商业的telnet类工具.用它 ...
- redis 在 php 中的应用(Server[ 服务器] 篇)
本文为我阅读了 redis参考手册 之后编写,注意 php_redis 和 redis-cli 的区别(主要是返回值类型和参数用法) 目录: Server(服务器) BGREWRITEAOF BGSA ...
- ios真机调试错误解决:Installation of apps is prohibited by a policy on the device
该问题的出现原因是手机中的访问权限被关闭了,打开方法如下: 设置->通用->访问限制->安装应用程序
- Oracle 拼接列数据的方法
select wm_concat(fphone) phone from dq_phone_ndtbdxz wm_concat(列名):把多列值,合并成一列,用,隔开.
- JProfiler远程监控
1. 服务端安装JProfiler(与客户端版本一致) 2. 客户端配置连接: A).session——integration wizards——New remote integration B) ...
- What’s Brewing for .NET Developers
Microsoft hosted its premier fall developer event – Connect(); // 2016 in New York on November 16-17 ...
- 用delphi制作无界面的activex控件
首先,您要了解: •COM的基本原理 •能被网页调用的非可视ActiveX控件必须是一种至少实现了IOleObject接口的TAutoObject组件 •利用Delphi向导生成的ActiveX控件必 ...
- iOS 6 新的快捷初始化写法
转:http://www.2cto.com/kf/201408/328974.html 下列简化写法是IOS6.0以后的新写法 NSNumber //简化前的写法: NSNumber *value1; ...
- WordPress基础:极简手动安装教程
1.下载WordPress 2.将解压后的文件夹,放到网站根目录,并重命名为你喜欢的目录如:w, 3.重命名文件wp-config-sample.php 为 wp-config.php,并进行配置 4 ...