“classpath”: 用于加载类路径(包括jar包)中的一个且仅一个资源;对于多个匹配的也只返回一个,所以如果需要多个匹配的请考虑“classpath*:”前缀;
无论是classpath还是classpath*都可以加载整个classpath下(包括jar包里面)的资源文件。
classpath只会返回第一个匹配的资源,查找路径是优先在项目中存在资源文件,再查找jar包。
- 文件名字包含通配符资源(如果spring-.xml,spring.xml), 如果根目录为”“, classpath加载不到任何资源, 而classpath*则可以加载到classpath中可以匹配的目录中的资源,但是不能加载到jar包中的资源
第三点的验证实例:
- classpath:notice*.txt
加载不到资源 - classpath*:notice*.txt
加载到resource根目录下notice.txt - classpath:META-INF/notice*.txt
加载到META-INF下的一个资源(classpath是加载到匹配的第一个资源,就算删除classpath下的notice.txt,他仍然可以 加载jar包中的notice.txt) - classpath:META-/notice.txt
加载不到任何资源 - classpath*:META-INF/notice*.txt
加载到classpath以及所有jar包中META-INF目录下以notice开头的txt文件 - classpath*:META-/notice.txt
只能加载到classpath下 META-INF目录的notice.txt
感谢大神,分析很到位
http://blog.csdn.net/zl3450341/article/details/9306983