Spring中context:annotation-config和context:component-scan区别

Spring中context:annotation-config和context:component-scan区别

  • <context:annotation-config/> 注解扫描是针对已经在 Spring 容器里注册过的 Bean,即特定的一些后置bean,能完成部分@标签的解析功能,但是还有部分功能不能用,作用有限。

  • <context:component-scan/> 不仅具备 context:annotation-config/ 的所有功能,还可以在指定的 package 下面扫描对应的 bean.

  • < context:annotation-config/>可以帮助我们识别@Antowired注解,但是不能帮我我们识别@Component、@Controller、@Service等这些注解。

总结

(1):<context:annotation-config />仅能够在已经在已经注册过的bean上面起作用。对于没有在spring容器中注册的bean,它并不能执行任何操作。

(2)context:component-scan除了具有<context:annotation-config />的功能之外,还具有自动将带有@component,@service,@Repository等注解的对象注册到spring容器中的功能。

原文链接:https://blog.csdn.net/m0_45406092/article/details/115209508

posted @ 2023-03-07 14:32  一个苦逼的23届毕业生  阅读(14)  评论(0编辑  收藏  举报