Is there a difference in the context annotation config and context component scan tags?
Click to see full answer
Accordingly, what is context annotation config />?
<context:annotation-config> is used to activate annotations in beans already registered in the application context (no matter if they were defined with XML or by package scanning).
Subsequently, question is, what is the difference between @component and @ComponentScan? Using the annotation @ComponentScan , you can tell Spring where do your Spring-managed components lie. On the other hand, @Component is a generic annotation for any Spring-Managed component. For example - If you create a class called Testing inside the package com.
Similarly, you may ask, what does context component scan do?
Moreover, <context:component-scan> recognizes bean annotations that <context:annotation-config> doesn't detect. Basically, <context:component-scan> detects the annotations by package scanning. To put it differently, it tells Spring which packages need to be scanned to look for the annotated beans or components.
How do you turn on annotation wiring?
To enable @Autowired, you have to register 'AutowiredAnnotationBeanPostProcessor', and you can do it in two ways :
- Include <context:annotation-config /> Add Spring context and <context:annotation-config /> in bean configuration file.
- Include AutowiredAnnotationBeanPostProcessor.