annotation-config vs(对比) component-scan
程序员文章站
2022-04-05 22:05:51
...
<cx:annotation-config/> 可以处理@Autowired,但是不能处理@Component, @Service, @Repository 所以如果你使用了@Component, @Service, @Repository就必须添加<cx:component-scan base-package="">.
<cx:component-scan ..>包含了<cx:annotation-config/>的功能,并且还可以处理@Component, @Service, @Repository, 所以你只要使用了<cx:component-scan ..>,
就不需要添加<cx:annotation-config/>
http://techidiocy.com/annotation-config-vs-component-scan-spring-core/
annotation-config : Annotation config main job is to activate all the annotations that are present in java beans and those are already registered either by defining in your application context file or being registered while component scanning. Important point is they need to be registered.
component-scan : Component scan can do everything that annotation config does , in addition to it it also registers the java classes as spring bean those are annotated with @Component , @Service ,@Repository etc.
<cx:component-scan ..>包含了<cx:annotation-config/>的功能,并且还可以处理@Component, @Service, @Repository, 所以你只要使用了<cx:component-scan ..>,
就不需要添加<cx:annotation-config/>
http://techidiocy.com/annotation-config-vs-component-scan-spring-core/
annotation-config : Annotation config main job is to activate all the annotations that are present in java beans and those are already registered either by defining in your application context file or being registered while component scanning. Important point is they need to be registered.
component-scan : Component scan can do everything that annotation config does , in addition to it it also registers the java classes as spring bean those are annotated with @Component , @Service ,@Repository etc.
推荐阅读
-
[视频]抄袭VS正品 小米对战巴慕达空气净化器拆解对比
-
京东华瑞1号和余额宝哪个更好些?国华华瑞1号vs余额宝收益率对比
-
苹果对战微软 MacBook vs Surface Pro 3规格价格对比
-
逻辑板拆解大小对比 新MacBook vs iPhone6
-
R语言 vs Python对比:数据分析哪家强?
-
Storm VS Flink ——性能对比
-
surface pro 2和ipad air哪个好?微软surface pro 2VS苹果ipad air对比评测
-
苹果对战微软 MacBook vs Surface Pro 3规格价格对比
-
逻辑板拆解大小对比 新MacBook vs iPhone6
-
6核战8核谁强!锐龙5 5600X VS. i7-11700K游戏性能对比评测