Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > jsp框架

Spring在web.xml中的配置详细介绍

来源:中文源码网    浏览:224 次    日期:2024-05-16 08:14:17
【下载文档:  Spring在web.xml中的配置详细介绍.txt 】


Spring在web.xml中的配置详细介绍
Spring在web.xml中的配置详细介绍
前言
在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制自动加载到容器中。在web项目中,配置文件加载到web容器中进行解析。目前,spring提供了两种加载器,以供web容器的加载:一种是ContextLoaderListener,另一种是ContextLoaderServlet。这两种在功能上完全相同,只是前一种是基于Servlet2.3版本中新引入的Listener接口实现,而后一种是基于Servlet接口实现,以下是这两种加载器在web.xml中的配置应用:
ContextLoaderListener

org.springframework.context.ContextLoaderListener

ContextLoaderServlet

context
org.springframework.context.ContextLoaderServlet
1

通过上面的配置,web容器会自动加载applicationcontext.xml初始化。
如果需要指定配置文件的位置,可通过context-param加以指定:

contextConfigLocation
/WEB-INF/myApplicationContext.xml

之后,可以通过WebApplicationContextUtils.getWebApplicationContext方法在web应用中获取applicationcontext的引用。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关内容