SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描! 
“Application类”是指SpringBoot项目入口类。
这个类的位置很关键: 
如果Application类所在的包为:com.boot.app,则只会扫描com.boot.app包及其所有子包,如果service或dao所在包不在com.boot.app及其子包下,则不会被扫描! 
即, 把Application类放到dao、service所在包的上级,com.boot.Application 
知道这一点非常关键,大多数情况下bean无法注入进来都是这个原因引起的。

本人的错误原因是:entity,service,serviceImpl,controller等这些包和Application.java     SpringBoot程序的入口不在同一个包且不在Application.java的子包中。

原因是:SpringBoot运行时所加载的包是Application.java本包及其子包的代码。所以根本扫描不到其他包,你怎么改注解都是错误的。

原因之二:就是bean加载顺序不对,比方说你的拦截器是在service加载之前就生成了,application在生成拦截器bean的时候怎么能找到service这个bean呢.

SpringBoot扫描不到类,注入失败A component required a bean of type 'XXService' that could...的更多相关文章

  1. SpringBoot中service注入失败(A component required a bean of type 'XXService' that could not found)

    先写了JUnit,发现启动不了,注释掉有问题的service也不可以.可能是因为spring开始时会加载所有service吧. 按照网友们的说法,一般需要检查: 1.入口类有没有写MapperScan ...

  2. 运行springboot项目报错:Field userMapper in XX required a bean of type 'xx' that could not be found.

    运行springboot项目报错: *************************** APPLICATION FAILED TO START ************************** ...

  3. Spring Cloud Ribbon负载均衡配置类放在Spring boot主类同级增加Exclude过滤后报Field config in com.cloud.web.controller.RibbonConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not b

    环境: Spring Cloud:Finchley.M8 Spring Boot:2.0.0.RELEASE 目录结构: 可以看到代码第13行的注释,我已经在@ComponentScan注解中添加了E ...

  4. 2. springboot启动报错:Field userMapper in com.service.UserService required a bean of type 'com.dao.UserMapper' that could not be found.

    报错信息: 2018-06-25 14:26:17.103  WARN 49752 --- [  restartedMain] ationConfigEmbeddedWebApplicationCon ...

  5. spring 类注入失败,解决之道

    1.今天偶尔发现的问题,如果你在一个类上面用了注解@Async,spring的异步注解之后,发现如果别的类用@Autowired导入这个类时会失败! 解决办法:用了@Async无非是想方便的用异步操作 ...

  6. 67. @Transactional的类注入失败【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] Spring的代理模式有两种:java自带的动态代理模式和cglib代理模式,cglib代码模式适用于没有接口的类,而java自带适用于接口类,默 ...

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

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

  8. springboot jpa mongodb 整合mysql Field in required a bean of type that could not be found Failed to load ApplicationContext

    1.完整报错 *************************** APPLICATION FAILED TO START *************************** Descripti ...

  9. SpringBoot扫描包提示找不到mapper的问题

    SpringBoot扫描包问题 报错信息:Consider defining a bean of type in your configuration 方法一: 使用注解 @ComponentScan ...

随机推荐

  1. Mysql 2019-07-01

  2. linux下用户切换

    Linux学习使用ubuntu17,ubuntu安装的时候没有超级用户root的密码. 设置系统root用户的密码,Ubuntu刚安装后,因为root没有默认密码,需要手动设定.以安装ubuntu时输 ...

  3. 常用命令--find

    语法 find path -option [ -print ] [-exec -ok command ] {} \; find . -maxdepth 1 -type f -exec mv {} /t ...

  4. kubernetes容器集群管理创建node节点kubeconfig文件

    1.创建TLS Bootstrapping Token 2.创建kubelet kubeconfig 3.创建kube-proxy kubeconfig 安装和设置kubectl [root@mast ...

  5. flex 的经典用法

    Document   11 21 31 41 51 61 71 81 91 101 111 121 131 141 151 161 171 181 191 201 211 221 231 241 25 ...

  6. ng2-file-upload插件在ionic3中的使用方法

    本文主要说明在ionic3中使用ng2-file-upload插件,上传多种类型文件(图片.word.excel.ppt.mp4等)的使用方法. 1.html代码: <button ion-bu ...

  7. Redis的备份与恢复

    备份 dump.rdb:RDB方式的备份文件 appendonly.aof:AOF方式的备份文件 rdb 备份处理 # 编辑redis.conf文件,找到如下参数,默认开启. save 900 1 s ...

  8. 简单递归____Fibonacci数列

    #include <stdio.h> int fun(int x) { ||x==) ; else return fun(x-1)+fun(x-2); } int main() { int ...

  9. 力扣 -- 寻找两个有序数组的中位数 Median of Two Sorted Arrays python实现

    题目描述: 中文: 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 你可以假设 nums ...

  10. Django创建工程项目以及工作原理

    一.Django 创建工作项目 1.创建 North 工程项目 (1)使用CMD命令行,切换到指定路径 django-admin.py startproject north (2)使用pycharm创 ...