spring配置里<context:annotation-config>和<context:component-scan>区别

annotation-config处理@autowired之类的注解(共有四类) 前提是注解作用的类已经被注册到spring容器里(bean id=“” class=“”) 

component-scan除了包含annotation-config的作用外,还能自动扫描和注册base-package下有@component之类注解的类,将其作为bean注册到spring容器里

所以配置文件如果有component-scan就不需要annotation-config了。

posted @ 2017-04-18 10:56  孙聪  阅读(2851)  评论(0编辑  收藏  举报