- Are
applicationContext.xml
andspring-servlet.xml
related anyhow in Spring Framework?
- Will the properties files declared in
applicationContext.xml
be available toDispatcherServlet
?
- 另一方面,为什么我需要
*-servlet.xml
分呢?为什么光是applicationContext.xml
还不够?
applicationContext.xml
and spring-servlet.xml
related anyhow in Spring Framework?applicationContext.xml
be available to DispatcherServlet
?*-servlet.xml
分呢?为什么光是applicationContext.xml
还不够? Spring允许您在父子层次 struct 中定义多个上下文.
applicationContext.xml
定义了用于"根webapp上下文"的bean,即与webapp相关联的上下文.
spring-servlet.xml
(或者你管它叫什么)为一个servlet的应用程序上下文定义bean.在一个webapp中可以有很多这样的应用,每个Spring servlet一个(例如spring1-servlet.xml
代表servlet spring1
,spring2-servlet.xml
代表servlet spring2
).
spring-servlet.xml
中的bean可以引用applicationContext.xml
中的bean,但反之亦然.
所有Spring MVC控制器都必须在spring-servlet.xml
上下文中运行.
在大多数简单的情况下,applicationContext.xml
上下文是不必要的.它通常用于包含webapp中所有servlet之间共享的bean.如果您只有一个servlet,那么就没有什么意义了,除非您对它有特定的用途.