spring中classpath和classpath*的配置区别
来源:互联网 发布:浙江柳林机械销售网络 编辑:程序博客网 时间:2024/05/18 03:59
在使用spring时,经常会看到类似 classpth:、classpath*: 这样的前缀,不管是加载spring xml配置文件还是其配置文件中加载资源文件都会看到这两种前缀配置,其实这两种前缀是有区别的,下面将举例详细解释。
[一]、测试项目准备
我们以spring中加载properties资源文件为例讲解,目录结构大致如下:
同时 在该项目的lib中添加一个测试的micmiu-test.jar包,jar包中的文件结构如下:
从准备的测试环境中我们可以看到在不同目录下的四个同名的application.properties资源文件。
[二]、测试代码:TestClassPath.java
[三]、测试结果
spring配置文件:applicationContext.xml 中两种不同的properties文件加载配置:
第一种:classpath:
这种配置下运行测试代码,日志信息中有关加载properties资源文件只有一条 如下:
第二种: classpath*:
这种配置下运行测试代码,日志信息中有关加载properties资源文件会有三条如下:
由此日志信息可知:
- 同名资源存在时,classpath: 只从第一个符合条件的classpath中加载资源,而classpath*: 会从所有的classpath中加载符合条件的资源
- classpath*:需要遍历所有的classpath,效率肯定比不上classpath,因此在项目设计的初期就尽量规划好资源文件所在的路径,避免使用classpath*来加载
本文介绍到此结束@Michael Sun.
原创文章,转载请注明: 转载自micmiu – 软件开发+生活点滴[ http://www.micmiu.com/ ]
本文链接地址: http://www.micmiu.com/j2ee/spring/spring-classpath-start/
0 0
- spring配置中classpath和classpath*的区别
- spring中classpath和classpath*的配置区别
- spring中classpath和classpath*的配置区别
- spring中classpath和classpath*的配置区别
- spring中classpath和classpath*的配置区别
- Spring中classpath*和classpath的区别
- Spring的classpath和classpath*的区别
- Spring中classpath*:与classpath:的区别
- spring中classpath与classpath*的区别
- spring classpath和classpath*的区别
- classpath和classpath*的配置区别
- Spring中classpath和classpath*的问题
- classpath 和 classpath*的区别
- classPath和classPath*的区别
- classpath: 和 classpath*:的区别
- classpath: 和classpath*:的区别
- classpath和classpath*的区别
- classpath和classpath*的区别
- springMVC中多个对象的数据绑定
- 欢迎使用CSDN-markdown编辑器
- centos6.7无线网卡驱动安装
- linux 常用命令小汇总
- Samtools说明文档网址变更
- spring中classpath和classpath*的配置区别
- switch()语句块的出口:break;
- CF345div2 C题 map映射的作用
- Andiord NDK和SDK下载网址
- 使用 code review 时 git push 失败
- postgre-隐藏系统列
- 双向map,通过value找到key,还有...
- nginx做反向代理实现负载均衡
- Vim实战指南(七):编程偏好配置