我是Spring MVC World的新手。今天我正在学习由STS生成的简单的"Hello World“示例:文件-> Spring模板项目-> Spring MVC项目
在web.xml中,我有DispatcherServlet的声明和it...Up处理的请求映射,在这里一切都好
在web.xml中,我还有这部分代码:
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>在阅读Spring文档中关于ContextLoaderListener的内容时,我读到这个类执行侦听器的引导来启动Spring根WebApplicationContext but...what,这到底是什么意思?
另一个疑问是,我传递给context...what的contextConfigLocation参数到底是什么?打开/WEB-INF/spring/root-context.xml文件,它似乎没有包含任何configuration...is,它是由我的模板项目创建过程自动创建的一个无效配置文件吗?在Spring项目中应该包含什么样的配置?
我认为在这个Hello World项目中没有使用和标签,因为如果我删除了这些标签,程序仍然会运行well....is,对吗?
发布于 2012-12-01 02:18:58
ContextLoaderListener是一个启动Spring容器的类。基本上,每个Spring应用程序都由几个bean和连接(对哪些bean相互依赖的声明性描述)组成。这个描述过去是用XML编写的(现在我们有注释、Java配置、CLASSPATH扫描等)。
没有Spring容器,bean只是Java类,Spring配置文件只是一个无用的XML文档。ContextLoaderListener读取该文件,找到您的类,实例化它们并连接。然后,所有的bean都被放入一个容器中。
此外,在应用程序关闭时,ContextLoaderListener会关闭上下文(如果需要清理,则关闭所有bean)。
https://stackoverflow.com/questions/13650695
复制相似问题