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

来源:互联网 发布:淘宝客2016年还好做吗 编辑:程序博客网 时间:2024/05/21 08:01

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

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

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


 

如果Bean是通过xml配置,想使用注解依赖注入,必须单独配置

       <context:annotation-config/>

阅读全文
0 0
原创粉丝点击