web.xml中,spring模块化加载xml方式
1:web.xml中添加监听器。
<listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
监听器作用为spring上下文在web容器初始化的时候加载spring相关配置。
查看源码可以看到依赖关系:
public class ContextLoaderListener extends ContextLoader implements ServletContextListener
父类ContextLoader中,有如下全局变量参数,为监听器获取初始化对象的引用值:
/*** Name of servlet context parameter (i.e., {@value}) that can specify the* config location for the root context, falling back to the implementation's* default otherwise.* @see org.springframework.web.context.support.XmlWebApplicationContext#DEFAULT_CONFIG_LOCATION*/public static final String CONFIG_LOCATION_PARAM = "contextConfigLocation";
注释中描述了这是指定了根上下文的位置,CONFIG_LOCATION_PARAM是上下文参数名称,如果没有,那默认位置为:XmlWebApplicationContext,我们详细看下这个类,DEFAULT_CONFIG_LOCATION默认/WEB-INF/applicationContext.xml这个文件为spring的context配置文件。其余参数指定文件夹位置,后缀名称。
public class XmlWebApplicationContext extends AbstractRefreshableWebApplicationContext {/** Default config location for the root context */public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml";/** Default prefix for building a config location for a namespace */public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/";/** Default suffix for building a config location for a namespace */public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml";
所以,web.xml中我们可以添加如下配置:
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath*:/config/spring/spring*.xml</param-value></context-param>
这样即实现了,config/spring/目录下,所有以spring字符串开头的xml配置文件。
效果图:
转载于:https://www.cnblogs.com/somewhater/p/8706919.html
web.xml中,spring模块化加载xml方式相关推荐
- 服务器启动时Webapp的web.xml中配置的加载顺序
一 1.启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点. 2.紧急着,容创建一个Ser ...
- idea中pom.xml中插件无法加载
每次涉及到maven插件,看见自己的pom.xml里面总是红色无法加载,刷新也不知道点哪边,这里只能自己设置一下maven插件的自动加载,这样就不用担心插件无法加载了. 选择file-setting- ...
- Qt工作笔记-把QTableWidget数据存为XML,启动时加载XML
运行截图如下: 添加好数据后保存: 此时保存的XML,如下图: 程序运行时会加载这些xml文件. 代码如下: widget.h #ifndef WIDGET_H #define WIDGET_H#in ...
- java spring 加载bean,Spring多种加载Bean方式解析
1 定义bean的方式 常见的定义Bean的方式有: 通过xml的方式,例如: ? 通过注解的方式,在Class上使用@Component等注解,例如 ? 通过在@Configuration类下的@B ...
- spring BeanFactory加载xml配置文件示例
项目目录结构如下: HelloWorld.java 1 package com.thief.demo; 2 3 public class HelloWorld { 4 5 public void sa ...
- 解决IDEA中pom.xml中不能自动加载jar包
网上找了好多方法,在这里总结一下,可以自查看看你的idea上哪里没有设置.(前提是你的maven中,setting.xml文件中已经配置好了镜像) 1.settings中设置 -Dmaven.wago ...
- Spring中加载xml配置文件的六种方式
Spring中加载xml配置文件的六种方式 博客分类: Spring&EJB XMLSpringWebBeanBlog 因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装 ...
- Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)...
本文原文连接: http://blog.csdn.net/bluishglc/article/details/7596118 ,转载请注明出处! 有时候你会发现过去一直启动正常的系统,某天启动时会报出 ...
- org.xml.sax.SAXParseException: Failed to read schema document错误的完美解决方法 以及 Spring如何加载XSD文件
有时候你会发现过去一直启动正常的系统,某天启动时会报出形如下面的错误: org.xml.sax.SAXParseException: schema_reference.4: Failed to rea ...
最新文章
- Azure Stack-1807 版本 配置10分钟、自动部署6小时-我的ASDK第7次实践
- dev c++ 64位_RHEL7.8添加本地源以及扩展GCC,C++的32位和静态库支持
- 给Ubuntu软件升级命令
- GetModuleHandle(NULL)获取当前DLL模块基址?
- gblfy_IDEA常用快捷键技巧
- 【codevs30521022】多米诺覆盖,二分图
- 文件服务器搭建_小型企业文件存储服务器的搭建四部曲
- (转)全文检索技术学习(二)——配置Lucene的开发环境
- 抢那么多封面,有那么多钱发红包吗?
- Odoo10参考系列--混合而有用的类
- 自动驾驶——标注工具(js+electron)的开发笔记(基于Create-React-App)
- CSDN - 屏蔽百度广告
- USACO 2.1 海明码(DFS)
- 2.scrapy 的使用
- 通过网址获得视频网站的视频信息包括优酷,土豆,56,酷6
- java info()方法_Java中的提供者getInfo()方法
- IC授权卡和复制卡的区别_DIY电脑——A卡和N卡有区别吗
- 数学公式快速计算方法
- android 2k屏分辨率,2K、4K、8K分辨率屏幕有用吗?看看它们怎么说!
- python中config(state=disabled)_解决python flask中config配置管理的问题
热门文章
- oSIP开发者手册 (二)
- oracle+long列,oracle中对LONG列进行查询
- pwm控制舵机转动角度程序_舵机的内部结构及工作原理
- threejs引擎中 环境光线与管道流动
- MFC小笔记:系统托盘实现
- coreboot学习9:ramstage阶段之设备初始化流程
- 【Zookeeper】基于Zookeeper实现分布式锁
- 【Elasticsearch】ES内存满问题排查思路
- 【clickhouse】clickhouse 表引擎 之 AggregatingMergeTree
- Doker : Docker 容器与宿主机共享文件