1

I was going through some of the Spring documentation and from there I got to know that <context:annotation-config> is subset of <context:component-scan>, which means that what we can achieve with the help of the <context:annotation-config> , we can achieve the same using the <context:component-scan> with some add on functionality (i.e, scanning the specified basePackage for any defined component).
So my question is what are the uses of these two?

didxga
  • 5,935
  • 4
  • 43
  • 58
Mukesh
  • 540
  • 1
  • 9
  • 13

1 Answers1

4

in simple words:
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.

Tahir Hussain Mir
  • 2,506
  • 2
  • 19
  • 26