<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>掃描解析之前是沒有任何作用的!