我们经常看到把spring的配置文件的加载地址定义在<context-param>中。
例如:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springbean-*.xml,classpath*:springbeans-*.xml
</param-value>
</context-param>
<context-param>的作用如下:
1,启动一个web项目时,容器(tomcat,jboss)会读取配置文件的<context-param>。
2,接着容器创建一个ServletContext(上下文),这个WEB项目所有部分都将共享这个上下文。
3,容器将<context-param>转化为键值对,交给ServletContext。
4,其中的参数可以通过getServletContext().getInitParameter("context/param")得到。
分享到:
相关推荐
<context-param> 和<init-param>的 区别代码 博文链接:https://xhy0422.iteye.com/blog/46319
NULL 博文链接:https://wy649898543.iteye.com/blog/1833263
了解web.xml的配置信息和加载顺序,有助于理解框架的流程,
本篇文章是对web.xml中在Servlet中获取context-param和init-param内的参数进行了详细的分析介绍,需要的朋友参考下
param><br> <param-name>FCKDeniedExtensionsImage</param-name><br> <param-value /><br> </context-param><br><br> <servlet><br> <servlet-name>Connector</servlet-name><br> <servlet-class><br> ...
<param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/app/service</param-value> </context-param> <!--接口管理--> <context-param> <param-name>resteasy.resources</param-name> ...
<param-name>logbackConfigLocation</param-name> <param-value>/WEB-INF/conf/logback.xml</param-value> </context-param> <listener> <listener-class>ch.qos.logback.ext.spring.web....
<param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext-*.xml,/WEB-INF/action-servlet.xml </param-value> </context-param> <context-param> <param-name>log4...
<param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/*.bean.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context....
<param-value>classpath:spring/app.xml,classpath:org/codehaus/xfire/spring/xfire.xml</param-value> </context-param> <!--配置xfire ws--> <servlet> <servlet-name>XFireServlet</servlet-name> ...
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-...
<!--该元素声明应用范围内的初始化参数--> <context-param> <!--声明描述信息-->...<param-name></param-name> <!--用于指定上下文参数的值--> <param-value></param-value> </context-param>
<param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/database.xml /WEB-INF/applicationContext.xml </param-value> </context-param> <listener> <listener-class> org....
<param-value>20</param-value> </context-param> 字段解释如下: com.sinoprise.web.WebVisitEventListener:网站活动的监听器 WebVisitLogger-DbDriver:网站使用的数据库驱动,目前仅支持PostgreSQL ...
-- <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> --> <param-value>classpath:beans.xml</param-value> </context-param> <filter> <filter-name>...
spring/applicationContext.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> ApplicationContext * * * *...
DOS命令使用方法(超全). ... http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 下边这是加入spring配置 --> <context-param> <param-name>contextConfigLocation... <param-value>UTF-8</param-value>