2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Difference between context:annotation-config vs context:component-scan

what is the functionality behind <context:annotation-config> and <context:component-scan>.

From what I"ve read they seem to handle different annotations (@Required, @Autowired etc vs @Component, @Repository, @Service etc) but also from what I"ve read they register the same bean post processor classes.


1) First big difference between both tags is that<context:annotation-config> is used to activate applied annotations in already registered beans in application context. Note that it simply does not matter whether bean was registered by which mechanism e.g. using<context:component-scan> or it was defined in application-context.xml file itself.

2) Second difference is driven from first difference itself. It does register the beans in context + it also scans the annotations inside beans and activate them. So <context:component-scan&gt; does what<context:annotation-config> does, but additionally it scan the packages and register the beans in application context.

Answer is