spring加载文件使用通配符
来源:互联网 发布:双十一淘宝一元秒杀 编辑:程序博客网 时间:2024/06/02 03:54
不管是在web应用还是非Web应用中我们都希望在一个目录下放置配置文件,然后spring启动时加载配置目录下所有配置文件初始化context,这个要怎么做么首先想到的是使用通配符如:
spring-*.xml
表示以spring-开头的xml文件
需要注意的是要加上URL前缀或协议告诉spring怎么加载文件.
参考org.springframework.util.ResourceUtils:
/** Pseudo URL prefix for loading from the class path: "classpath:" */public static final String CLASSPATH_URL_PREFIX = "classpath:";/** URL prefix for loading from the file system: "file:" */public static final String FILE_URL_PREFIX = "file:";/** URL protocol for a file in the file system: "file" */public static final String URL_PROTOCOL_FILE = "file";/** URL protocol for an entry from a jar file: "jar" */public static final String URL_PROTOCOL_JAR = "jar";/** URL protocol for an entry from a zip file: "zip" */public static final String URL_PROTOCOL_ZIP = "zip";/** URL protocol for an entry from a JBoss jar file: "vfszip" */public static final String URL_PROTOCOL_VFSZIP = "vfszip";/** URL protocol for a JBoss VFS resource: "vfs" */public static final String URL_PROTOCOL_VFS = "vfs";/** URL protocol for an entry from a WebSphere jar file: "wsjar" */public static final String URL_PROTOCOL_WSJAR = "wsjar";/** URL protocol for an entry from an OC4J jar file: "code-source" */public static final String URL_PROTOCOL_CODE_SOURCE = "code-source";/** Separator between JAR URL and file path within the JAR */public static final String JAR_URL_SEPARATOR = "!/";如要加载classpath下所有以spring-开头的xml文件应该这样写:
classpath:spring-*.xml又如要加载f:/config下下所有以spring-开头的xml文件应该这样写:
file:f:/config/*.xml
- spring加载文件使用通配符
- Spring使用通配符自动加载hibernate映射文件生成sessionFactory
- Spring antmatcher 使用路径通配符加载Resource,
- Spring AntMatcher 使用路径通配符加载Resource
- Spring使用通配符自动加载hibernate映射文件生成sessionFactory (转载)
- Spring加载路径中的通配符
- 使用路径通配符加载Resource,
- 使用路径通配符加载Resource
- 使用路径通配符加载Resource,
- Spring的 classpath 通配符加载配置文件
- Spring的 classpath 通配符加载配置文件
- Spring如何利用classpath通配符加载配置文件
- Spring的 classpath 通配符加载配置文件
- Spring中classpath*:使用通配符加载jar当中的资源无效的原因
- struts2多配置文件使用通配符加载
- 软件工程:使用路径通配符加载Resource
- Struts2 spring 多配置文件使用通配符
- spring通配符?,*,**
- 看奇迹的背后:淘宝复杂在哪里?
- main函数参数解析
- UINavgationBar之UIBarButtonItem
- Android控件开发之GridView
- C++图像处理 -- 图像翻转(镜像)
- spring加载文件使用通配符
- 将字符串str1与str2连接起来保存到str3中
- 我理解的ACID
- 调制解调器和路由器的连接
- HEVC学习(七) —— 帧内预测系列之五
- HEVC学习(八) —— 以SAO为例浅析跟踪代码方法
- 重叠字符串
- vb调用蜂鸣器制造音阶
- POJ2253 青蛙泡妞(单源最短路径变形)