文章详情页
java - Spring Boot中@EnableAutoConfiguration和@ComponengScan有什么区别?
浏览:60日期: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. html5 - css3scale和rotate同时使用转换成matrix写法该如何转换?2. css - width设置为100%之后列表无法居中3. thinkjs - 使用mysql搭建cms应该如何设计表?或怎样开始?4. 求大神帮我看看是哪里写错了 感谢细心解答5. mysql 获取时间函数unix_timestamp 问题?6. python3的各种库的官方文档中文版在哪儿可以找到7. php自学从哪里开始?8. javascript - jqery ajax问题9. python - nginx为什么不能反代图片?10. javascript - 小demo:请教怎么做出类似于水滴不断扩张的效果?
排行榜
