<context-annotation-config/>
该配置的主要作用是“激活”已声明的bean,即“激活”spring容器内配置的bean。
如:在spring容器内配置了<bean name="demo" class="com.example.Demo"></bean>,那么则可以使用@Autowired注解将demo注入相应对象中。但是,该配置对@Component、@Controller、@Service、@Repository注解的,但没有在spring容器注册过的bean无效。
<context:component-scan base-package="" />
该配置包含了<context-annotation-config />配置的作用,与之不同的是:该配置可以扫描base-package指定包下@Component、@Controller、@Service、@Repository注解并将被注解bean注册到spring容器内,使之生效。
注意:1. 当这两个配置同时配置时,<context-annotation-config />将失效,以<context:component-scan base-package="" />为准!
2. @Component、@Controller、@Service、@Repository这些注解本身并不具有声明注册bean的功能,在没有<context:component-scan>扫描解析之前是没有任何作用的!