SpringBoot扫描不到类,注入失败A component required a bean of type 'XXService' that could...
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...的更多相关文章
- SpringBoot中service注入失败(A component required a bean of type 'XXService' that could not found)
先写了JUnit,发现启动不了,注释掉有问题的service也不可以.可能是因为spring开始时会加载所有service吧. 按照网友们的说法,一般需要检查: 1.入口类有没有写MapperScan ...
- 运行springboot项目报错:Field userMapper in XX required a bean of type 'xx' that could not be found.
运行springboot项目报错: *************************** APPLICATION FAILED TO START ************************** ...
- 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 ...
- 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 ...
- spring 类注入失败,解决之道
1.今天偶尔发现的问题,如果你在一个类上面用了注解@Async,spring的异步注解之后,发现如果别的类用@Autowired导入这个类时会失败! 解决办法:用了@Async无非是想方便的用异步操作 ...
- 67. @Transactional的类注入失败【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] Spring的代理模式有两种:java自带的动态代理模式和cglib代理模式,cglib代码模式适用于没有接口的类,而java自带适用于接口类,默 ...
- spring boot注入error,Consider defining a bean of type 'xxx' in your configuration问题解决方案
经常出现这问题一定是非spring生态圈的@标签 没被spring引入,如mybatis等 因为在默认情况下只能扫描与控制器在同一个包下以及其子包下的@Component注解,以及能将指定注解的类自动 ...
- 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 ...
- SpringBoot扫描包提示找不到mapper的问题
SpringBoot扫描包问题 报错信息:Consider defining a bean of type in your configuration 方法一: 使用注解 @ComponentScan ...
随机推荐
- Selenium:WebDriverApi接口详解
浏览器操作 # 刷新 driver.refresh() # 前进 driver.forward() # 后退 driver.back() Cookie操作 # 根据cookieKey,获取cookie ...
- js 监听input 实现数据绑定
<!DOCTYPE html> <html> <head> <script> function checkField(val) { //alert(&q ...
- Robot Framework +钉钉通知(Dingding[钉钉] Plugin)构建通知
1.点击钉钉个人头像进入[机器人管理] 2.添加自定义机器人 3.创建机器人,选择通知群 4.完善机器人信息 5.复制机器人token(只需要连接access_token后面token) 6.进入je ...
- 看不到但摸得到的捣蛋鬼---Zero Width Space
看不到但摸得到的捣蛋鬼---Zero Width Space 1.情况如何? 昨天,"某某某"的代码出现了一个bug.大概是这个情况: 有一个提示信息,需要展示,大概这样: 这行文 ...
- border-radius使用的一些问题(不起作用?)
出现这种问题,border-radius没有达到自己想要的效果(小程序中) 原因:border-radius定义了border的圆角,未定义span元素的圆角范围 解决:不设置border,则bord ...
- JavaScript_基础笔记
javaScript基础:概念:一门客户端脚本语言 运行在客户端浏览器中的,每一个浏览器都有javaScript的解析引擎 脚本语言:不需要编译,直接可以被浏览器解析执行功能区: 可以来增强用户和ht ...
- 开源的android客户端,ghost网站
https://github.com/TryGhost/Ghost-Android http://docs.ghostchina.com/zh/
- setattr(object, name, value)¶
This is the counterpart of getattr(). The arguments are an object, a string and an arbitrary value. ...
- Android processDebugManifest 异常
1.使用 gradlew processDebugManifest --stacktrace 进行排查; 2.异常: processDebugManifest (Thread[Execution wo ...
- 【leetcode】934. Shortest Bridge
题目如下: In a given 2D binary array A, there are two islands. (An island is a 4-directionally connecte ...