Java uses a wildcard path to load Resource

Preface

Spring provides a powerful Ant wildcard pattern matching, matching path from a number of resources.

Ant path wildcards

"?" Ant path wildcard support, "*", "*" wildcard matching note does not include a directory separator "/": 

"? ": Match a character , such as "? Config .xml" will match "config1.xml";

"* ": Matches zero or more strings , such as "cn / * / config.xml" will match "cn / javass / config.xml", but does not match match "cn / config.xml"; and "cn /config-*.xml "will match" cn / config-dao.xml ";

"** ": matching path zero or more directories , such as "cn / ** / config.xml" will match "cn /config.xml", also matches "cn / javass / spring / config.xml " ; and ". cn / javass / config - ** xml" will match "cn / javass / config-dao.xml ", i.e., the "**" as two "*" process.

classpath和classpath*

Spring when loading classpath resources in addition to providing the prefix "classpath:" to support the load of a Resource, but also provide a prefix "classpath *:" to support the load all the classpath Resource match. 

A, "CLASSPATH ":  for loading one and only one resource class path (including jar package) is; only returns a plurality of matching, so if multiple matching consider "classpath *:" prefix; 

Two, "CLASSPATH * :"  all resources for loading classes path (including jar package) are matched. Classpath wildcard use "ClassLoader" the " Enumeration < the URL ofgetResources ( String  name)" method to find resources before a wildcard, then get resources by matching pattern matching. Such as "classpath:. META-INF / * LIST" will be loaded first before the wildcard directory "META-INF", then the sub-path traversal path in order to get matching resources to match.

Where classpath used

In the project compiled package, the root directory META-INFand BOOT-INF. This time, we can see this folder classes, which is what we are looking for classpath.

It should be mentioned is that the item may depend on the underlying jar package, such as: api reference layer is required jar package dal layer. I want to say is all dependent jar package classes are at the same level.

Examples of co-understand:

This code api jar package layer.

This resource is jar package dal layer

to sum up

java resource loading forever, as well as in-depth, do not have time, that's all.

Guess you like

Origin www.cnblogs.com/knowledgesea/p/11199350.html