文章正文
Spring Boot的Component Scan原理
【文档】2020-04-23
简介Spring Boot的Component Scan原理
@ComponentScan
“告诉Spring到哪里搜索”称为组件扫描。
Spring Boot项目中的组件扫描
如果你的其他包层次结构位于使用@SpringBootApplication标注主应用程序下方,则隐式组件扫描将自动涵盖。也就是说,不要明确标注@ComponentScan,Spring Boot会自动搜索当前应用主入口及其下方子。
如果其他包中的bean /组件不在当前主包路径下面,,则应手动使用@ComponentScan 添加
如果使用了@ComponentScan ,那么Spring Boot就全部依赖你的定义,如果定义出错,会出现autowired时出错,报a bean of type that could not be found错误。
与组件扫描相关的错误
No qualifying bean of type found 或 在Intellij Idea中显示 incorrectly saying no beans of type found for autowired repository
上述两个问题的根本原因相同 - 组件未被Spring boot发现。
@Component和@ComponentScan有什么区别?
@Component表示标记组件。
@ComponentScan扫描被标记的组件
打赏支持
感谢您的支持,加油!
打开微信扫码打赏,你说多少就多少
找书费时,联系客服快速查找!
在线客服8:30-22:30,若离线请留言!
获取教程,请联系在线客服!
在线客服8:30-22:30,若离线请留言!
热门阅读
-
20篇:英美现当代散文 陆谷孙等选编 上海:复旦大学出版社 PDF 9787309082647 出版时间:2011.pdf
20篇:英美现当代散文 陆谷孙等选编 上海:复旦大学出版社 PDF 9787309082647 出版时间:2011.pdf ...
-
材料力学解题指导 马红艳主编 北京:科学出版社 PDF 9787030400543 出版时间:2014.pdf
材料力学解题指导 马红艳主编 北京:科学出版社 PDF 9787030400543 出版时间:2014.pdf ...
-
疯癫与文明_米歇尔·福柯 北京:生活·读书·新知三联书店 PDF 97875413129287 出版时间:2007.04.pdf
疯癫与文明_米歇尔·福柯 北京:生活·读书·新知三联书店 PDF 97875413129287 出版时间:2007.04.pdf ...
-
蒙古秘史 余大钧译注 呼和浩特:内蒙古大学出版社 PDF 9787566505460 2014.pdf
蒙古秘史 余大钧译注 呼和浩特:内蒙古大学出版社 PDF 9787566505460 2014.pdf ...
-
中国画像石全集 第3卷 山东汉画像石 中国画像石全集编辑委员会,焦德森主编 济南:山东美术出版社 PDF 7533014251 2000.pdf
中国画像石全集 第3卷 山东汉画像石 中国画像石全集编辑委员会,焦德森主编 济南:山东美术出版社 PDF 7533014251 2000.pdf ...
-
萧克回忆录 萧克著 北京:解放军出版社 PDF 978725506533383 出版时间:1997.pdf
萧克回忆录 萧克著 北京:解放军出版社 PDF 978725506533383 出版时间:1997.pdf ...
-
国史大纲 新校本 下 钱穆著 北京:九州出版社 PDF 9787510809941 出版时间:2011.pdf
国史大纲 新校本 下 钱穆著 北京:九州出版社 PDF 9787510809941 出版时间:2011.pdf ...
-
国史大纲 新校本 上 钱穆著 北京:九州出版社 PDF 9787510809941 出版时间:2011.pdf
国史大纲 新校本 上 钱穆著 北京:九州出版社 PDF 9787510809941 出版时间:2011.pdf ...
-
罗马国史大纲 (古罗马)尤特罗庇乌斯著 上海:上海人民出版社 PDF 9787208098541 2011.pdf
罗马国史大纲 (古罗马)尤特罗庇乌斯著 上海:上海人民出版社 PDF 9787208098541 2011.pdf ...
-
精神的丰碑 焦裕禄 候红,霍传富,董来往主编 郑州:河南大学出版社 PDF 9787564913847 2014.pdf
精神的丰碑 焦裕禄 候红,霍传富,董来往主编 郑州:河南大学出版社 PDF 9787564913847 2014.pdf ...