小编典典

Spring Framework中applicationContext.xml和spring-servlet.xml之间的区别

spring

  • applicationContext.xmlspring-servlet.xmlSpring Framework中相关吗?
  • 声明的属性文件applicationContext.xml是否可用于DispatcherServlet
  • 在相关说明中,为什么我根本不需要*-servlet.xml?为什么一个applicationContext.xml人不够?

阅读 741

收藏
2020-04-11

共1个答案

小编典典

Spring使你可以在父子层次结构中定义多个上下文。

applicationContext.xml用于“根web应用上下文”,即与该web应用程序相关联的上下文定义了。

spring-servlet.xml(或任何你称呼它)定义了一个servlet的应用程序上下文中的豆。一个Web应用程序中可以有许多这样的应用程序,每个Spring Servlet都有一个(例如spring1-servlet.xmlservlet spring1spring2-servlet.xmlservlet spring2)。

中的Bean spring-servlet.xml可以引用中的Bean applicationContext.xml,反之亦然。

所有Spring MVC控制器必须位于spring-servlet.xml上下文中。

在大多数简单情况下,applicationContext.xml上下文是不必要的。它通常用于包含web应用程序中所有servlet之间共享的bean。如果你只有一个servlet,那么除非你有特定用途,否则没有太多意义。

2020-04-11