“classpath:”之间的区别是什么?和“classpath:/”在Spring XML中? [英] What is the difference between "classpath:" and "classpath:/" in Spring XML?

查看:446
本文介绍了“classpath:”之间的区别是什么?和“classpath:/”在Spring XML中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些Spring XML配置文件,有时它们使用classpath:/datasource.xml,有时还使用classpath:datasource。 xml的。这两者之间是否存在差异,或者是前导 / 可选/隐含/冗余?

I am working on some Spring XML configuration files and sometimes they use "classpath:/datasource.xml" and sometimes "classpath:datasource.xml". Is there a difference between the two or is the leading / optional / implied / redundant?

推荐答案

我认为这两者之间没有任何区别。您将看到的最大区别是相对路径和类路径位置上的*

I don't see any difference between these two. The biggest difference that you will see is that the relative path and the * on the classpath location

以下是 Spring Resources ,查找4.7.2.2节

Here is an excerpt from Spring Resources, look for section 4.7.2.2

Classpath *:

classpath *:前缀也可以与位置路径的其余部分中的PathMatcher模式结合使用,例如的classpath *:META-INF / * - beans.xml文件。在这种情况下,解析策略非常简单:在最后一个非通配符路径段上使用ClassLoader.getResources()调用来获取类加载器层次结构中的所有匹配资源,然后关闭每个资源相同的PathMatcher解析策略上面描述的用于通配符子路径。

Classpath*:
The "classpath*:" prefix can also be combined with a PathMatcher pattern in the rest of the location path, for example "classpath*:META-INF/*-beans.xml". In this case, the resolution strategy is fairly simple: a ClassLoader.getResources() call is used on the last non-wildcard path segment to get all the matching resources in the class loader hierarchy, and then off each resource the same PathMatcher resoltion strategy described above is used for the wildcard subpath.

这意味着像classpath *:*。xml这样的模式将不会从jar文件的根,但只来自扩展目录的根目录。这源于JDK的ClassLoader.getResources()方法中的限制,该方法仅返回传入的空字符串的文件系统位置(指示搜索的潜在根)。

This means that a pattern like "classpath*:*.xml" will not retrieve files from the root of jar files but rather only from the root of expanded directories. This originates from a limitation in the JDK's ClassLoader.getResources() method which only returns file system locations for a passed-in empty string (indicating potential roots to search).

这篇关于“classpath:”之间的区别是什么?和“classpath:/”在Spring XML中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆