annotation-config 与 component-scan区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jingyangV587/article/details/80384819

spring配置中context:annotation-config 与 context:component-scan 区别

1)context:annotation-config可以理解为注解解析器,解析诸如@autowired,@Resource之类的注解。前提是注解作用的类已经被注册到spring容器里。
2)context:component-scan除了包含context:annotation-config所有的功能之外还可以自动扫描和注册base-package下有诸如@component之类注解的类,并将其作为bean注册到spring容器里。
总结:有component-scan就不需要annotation-config了。

猜你喜欢

转载自blog.csdn.net/jingyangV587/article/details/80384819