文章详情页
java - Spring Boot中@EnableAutoConfiguration和@ComponengScan有什么区别?
浏览:136日期:2023-12-12 13:47:47
问题描述
现在的新版spring boot中@SpringBootApplication已经等价于@Configuration, @ComponentScan, @EnableConfiguration。请问@EnableAutoConfiguration和@ComponengScan之间有什么区别?既然@EnableAutoConfiguration可以自动扫描路径下面的所有bean,那么@ComponentScan似乎就没有存在的必要了?
问题解答
回答1:1.@EnableAutoConfiguration 主要是用来开启自动配置是扫描jar包下,配置了META-INF/spring.factories里面的类和针对当前包以及子包下的自定义组件的(也就是归spring管理的)2.@ComponengScan是用来配置自定义组件的(也就是归spring管理的),可以指定base路径orBaseClass
如果要加载的类不在@EnableAutoConfiguration下不会被加载,而且@ComponentScan为spring-context包下的类,是已经存在N久的用于在<context:component-scan>
回答2:@ComponentScan 可以扫描你引入的jar里面的package
标签:
java
相关文章:
1. javascript - 为什么我的vue里的router-link不起作用2. javascript - 求助Angular 跨控制器调用方法可行吗?3. CSS更改未得到反映。为什么?4. 用户在微信小程序支付成功以后,财务在微信支付后台用交易单号能查到这笔订单 但财务说钱没有入对公账号?5. javascript - node redirect重定向失败6. javascript - JS使用ele.style.backgoundImage = ’’ =’none’取消背景图片都无效7. a标签跨域下载文件能否重命名?8. android - weex 项目createInstanceReferenceError: Vue is not defined9. javascript - 如图,百度首页,查看源代码为什么什么都没有?10. pdo 写入到数据库的内容为中文的时候写入乱码
排行榜
