java spring-“ classpath:”和“ classpath:*”前缀
java spring-“ classpath:”和“ classpath:*”前缀
stackoverflow:Spring Class Path前缀差异
这 classpath*:conf/appContext.xml 仅意味着将在类路径上所有罐子中的所有罐子中的conf文件夹下的所有appContext.xml文件都被拾取并加入一个大型应用程序上下文。
相比之下, classpath:conf/appContext.xml只会加载一个这样的文件……在您的类路径上找到的第一个文件。
一件非常重要的事情 - 如果您使用*和Spring没有匹配,它不会抱怨。如果您不使用*并且没有匹配项,则上下文将不会启动!
Spring XML中的“ classpath:classpath”和“ classpath:/”有什么区别?
我认为这两个之间没有任何区别。您将看到的最大区别是相对路径和 * class路径上的*
这是春季资源的摘录,查找第4.7.2.2节
ClassPath*:
classpath*:例如,前缀也可以与位置路径的其余部分中的pathmatcher模式结合在一起 classpath*:META-INF/*-beans.xml 。在这种情况下,分辨率策略非常简单: ClassLoader.getResources()调用在最后一个非Wildcard路径段中使用,以获取类加载器层次结构中的所有匹配资源,然后在每个资源中使用相同的PathMatcher Resoltion策略上面描述的是通配符子路。
这意味着类似classpath*:*.xml不会从JAR文件的根部检索文件,而仅从扩展的目录的根部中检索文件。这起源于JDK的ClassLoader.getResources()方法中的限制,该方法仅返回传递的空字符串的文件系统位置(指示搜索的潜在根)。
StackOverflow: Spring classpath prefix difference
The classpath*:conf/appContext.xml simply means that all appContext.xml files under conf folders in all your jars on the classpath will be picked up and joined into one big application context.
In contrast, classpath:conf/appContext.xml will load only one such file… the first one found on your classpath.
One very important thing - if you use the * and Spring finds no matches, it will not complain. If you don’t use the * and there are no matches, the context will not start up!
What is the difference between “classpath:” and “classpath:/” in Spring XML?
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
Here is an excerpt from Spring Resources, look for section 4.7.2.2
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.
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).

浙公网安备 33010602011771号