Spring中指定applicationContext.xml等资源配置文件位置
来源:互联网 发布:lol网络关注 编辑:程序博客网 时间:2024/06/10 21:18
1.首先看看文件的位置
2.接下来看与资源文件位置相关的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVC</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath*:config/applicationContext.xml</param-value> -->
<param-value>/WEB-INF/classes/config/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!-- <param-value>classpath*:config/Springmvc-servlet.xml</param-value> -->
<param-value>/WEB-INF/classes/config/Springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
3. 配置文件说明
(1)
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
可以理解为Spring中的一个监听器,作用是启动web容器是自动装配ApplicationContext文件的配置信息。
(2)
<context-param> <param-name>contextConfigLocation</param-name> <!-- <param-value>classpath*:config/applicationContext.xml</param-value> -->
<param-value>/WEB-INF/classes/config/applicationContext.xml</param-value> </context-param>这段是用于指定applicationContext.xml等配置文件的位置,通过context-param指定。
***这里说明classpath是指WEB-INF文件夹下的classes目录;
***classpath与classpath*区别:
前者只会到你的class路劲中查找文件;
后者包含class路径和jar文件中的路劲。
(3)如果applicationContext.xml放在src目录下,则配置如下
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param>如果配置在WEB-INF下面,则web.xml文件中配置如下:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/applicationContext*.xml</param-value> </context-param>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/applicationContext*.xml</param-value></context-param>(4)多个配置文件加载
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:conf/spring/applicationContext_core*.xml, classpath*:conf/spring/applicationContext_dict*.xml, classpath*:conf/spring/applicationContext_hibernate.xml,或者
...... </param-value> </context-param>
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:**/applicationContext-*.xml</param-value></context-param>"**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。
- Spring中指定applicationContext.xml等资源配置文件位置
- mybatis中 mapper.xml文件中,获取数组中指定的位置的数据
- spring xml配置文件中指定的xsd文件读取不到了org.xml.sax.SAXParseException:
- applicationContext.xml文件放置位置
- 向xml文档中指定位置上添加节点
- javaNIO局部修改文件中指定位置的部分数据
- Spring中applicationContext.xml位置问题
- Spring的applicationContext.xml文件
- Spring的applicationContext.xml文件
- Spring的applicationContext.xml文件
- Spring的applicationContext.xml文件
- Spring applicationContext.xml文件解析
- spring mvc 怎么指定spring.xml的配置文件,在web.xml中指定
- 详解Spring的applicationContext.xml文件
- 详解Spring的applicationContext.xml文件
- 详解Spring的applicationContext.xml文件
- 读取applicationContext.xml(spring配置文件)文件
- Spring中 applicationContext.xml文件标头
- 以下程序输出结果是____。
- 获取项目当前路径
- POJ 3626 Mud Puddles(BFS)【模板】
- 计算机网络面试题
- Classes More Than 5 Students
- Spring中指定applicationContext.xml等资源配置文件位置
- 详解Spring Cloud Config
- [LeetCode]167. Two Sum II
- Java中关键字的大致含义
- mybatis基础--作用域和生命周期
- 《javascrip编程精解》第二版习题练习(未完,根据自己学习进度更新)
- Android中static关键字的理解,及几个面试点
- 自定义控件三部曲之动画篇(八)——PropertyValuesHolder与Keyframe
- (贪心)Codeforces Round #427 B. The number on the board