有关Spring web.xml< context-param>的一些信息和< listener> tag(简称Hello World示例) [英] Some information about Spring web.xml <context-param> and <listener> tag (referred to an Hello World example)

查看:116
本文介绍了有关Spring web.xml< context-param>的一些信息和< listener> tag(简称Hello World示例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring MVC World的新手。
今天我正在研究STS生成的简单Hello World示例:文件---> Spring模板项目---> Spring MVC项目

I am quite new in the Spring MVC World. Today I am studing the simple "Hello World" Example generated by STS doing: File ---> Spring Template Project ---> Spring MVC Project

在web.xml中,我有DispatcherServlet的声明和由它处理的请求映射......到这里一切都好了

In the web.xml I have the declaration of the DispatcherServlet and the request mapping handled by it...Up to here everything ok

在web.xml中我也有这部分代码:

In the web.xml I have also this part of code:

<!-- 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>

阅读关于ContextLoaderListener的Spring文档我读到这个类执行监听器的bootstrap来启动Spring的root WebApplicationContext但是......究竟是什么意思?

Reading the Spring documentation about ContextLoaderListener I read that this class execute the bootstrap of the listener to start up Spring's root WebApplicationContext but...what it means exactly?

另一个疑问是关于我传递给我的上下文的contextConfigLocation参数......究竟是什么?打开/WEB-INF/spring/root-context.xml文件似乎它不包含任何配置......它是由我的模板项目创建过程自动创建的void配置文件吗? Spring项目中应该包含哪种配置?

An other doubt is about the contextConfigLocation parameter that I am passing to my context...what is exactly? Opening the /WEB-INF/spring/root-context.xml file it seems that it do not contain any configuration...is it a void configuration file created automatically by my template project creation process? what kind of configuration should contain in a Spring project?

我认为这个Hello World项目中没有使用标签,因为如果我删除了这些标签,那么项目仍然是运行良好....是不是?

I think tath the and the tags are not used in this Hello World project because if I delete these tag the projext still run well....is it right?

推荐答案

ContextLoaderListener 是一个启动Spring容器的类。基本上每个Spring应用程序都包含几个bean和接线(哪些bean相互依赖的声明性描述)。这个描述历史上用XML编写(现在我们有注释,Java配置,CLASSPATH扫描等)。

ContextLoaderListener is a class that starts Spring container. Basically every Spring application consists of several beans and wiring (declarative description of which beans depend on each other). This description was historically written in XML (these days we have annotations, Java configuration, CLASSPATH scanning, etc.)

没有Spring容器,你的bean只是Java类和Spring配置file只是一个无用的XML文档。 ContextLoaderListener 读取该文件,查找您的类,实例化它们和连线。然后将所有bean放在容器中。

Without Spring container your beans are just Java classes and Spring configuration file is just a useless XML document. ContextLoaderListener reads that file, finds your classes, instantiates them and wires. All your beans are then placed inside a container.

另外 ContextLoaderListener 关闭上下文(如果关闭所有bean,则关闭应用程序关闭时需要进行一些清理。

Additionally ContextLoaderListener closes the context (shutting down all the beans if they need some cleanup) on application shutdown.

这篇关于有关Spring web.xml&lt; context-param&gt;的一些信息和&lt; listener&gt; tag(简称Hello World示例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆