annotation-config vs(对比) component-scan

[size=small]<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/>

[url]http://techidiocy.com/annotation-config-vs-component-scan-spring-core/[/url]

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.[/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值