annotation-config vs(对比) component-scan

<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.

你可能感兴趣的:(spring,annotation,config,component,scan)