@@ -8,6 +8,7 @@ Spring. It includes the following topics:
8
8
* <<resources-resource>>
9
9
* <<resources-implementations>>
10
10
* <<resources-resourceloader>>
11
+ * <<resources-resourcepatternresolver>>
11
12
* <<resources-resourceloaderaware>>
12
13
* <<resources-as-dependencies>>
13
14
* <<resources-app-ctx>>
@@ -31,7 +32,7 @@ such as a method to check for the existence of the resource being pointed to.
31
32
32
33
33
34
[[resources-resource]]
34
- == The Resource Interface
35
+ == The ` Resource` Interface
35
36
36
37
Spring's `Resource` interface located in the `org.springframework.core.io.` package is
37
38
meant to be a more capable interface for abstracting access to low-level resources. The
@@ -176,7 +177,7 @@ work.
176
177
177
178
178
179
[[resources-implementations]]
179
- == Built-in Resource Implementations
180
+ == Built-in ` Resource` Implementations
180
181
181
182
Spring includes several built-in `Resource` implementations, including but not limited to
182
183
the following:
@@ -242,6 +243,7 @@ transformations but performing all operations via the `java.nio.file.Files` API.
242
243
supports resolution as a `File` and as a `URL`.
243
244
244
245
246
+
245
247
[[resources-implementations-pathresource]]
246
248
=== `PathResource`
247
249
@@ -293,8 +295,9 @@ single-use `InputStreamResource`.
293
295
294
296
295
297
298
+
296
299
[[resources-resourceloader]]
297
- == The `ResourceLoader`
300
+ == The `ResourceLoader` Interface
298
301
299
302
The `ResourceLoader` interface is meant to be implemented by objects that can return
300
303
(that is, load) `Resource` instances. The following listing shows the `ResourceLoader`
@@ -416,8 +419,66 @@ objects:
416
419
417
420
418
421
422
+ [[resources-resourcepatternresolver]]
423
+ == The `ResourcePatternResolver` Interface
424
+
425
+ The `ResourcePatternResolver` interface is an extension to the `ResourceLoader` interface
426
+ which defines a strategy for resolving a location pattern (for example, an Ant-style path
427
+ pattern) into `Resource` objects.
428
+
429
+ [source,java,indent=0,subs="verbatim,quotes",role="primary"]
430
+ .Java
431
+ ----
432
+ public interface ResourcePatternResolver extends ResourceLoader {
433
+
434
+ String CLASSPATH_ALL_URL_PREFIX = "classpath*:";
435
+
436
+ Resource[] getResources(String locationPattern) throws IOException;
437
+
438
+ }
439
+ ----
440
+ [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
441
+ .Kotlin
442
+ ----
443
+ interface ResourcePatternResolver: ResourceLoader {
444
+
445
+ @JvmField
446
+ val CLASSPATH_ALL_URL_PREFIX: String = "classpath*:"
447
+
448
+ @Throws(IOException::class)
449
+ fun getResources(locationPattern: String): Resource[]
450
+
451
+ }
452
+ ----
453
+
454
+ As can be seen above, this interface also defines a special `classpath*:` resource prefix
455
+ for all matching resources from the class path. Note that the resource location is
456
+ expected to be a path without placeholders in this case -- for example,
457
+ `classpath*:/config/beans.xml`. JAR files or different directories in the class path can
458
+ contain multiple files with the same path and the same name. See
459
+ <<resources-app-ctx-wildcards-in-resource-paths>> and its subsections for further details
460
+ on wildcard support with the `classpath*:` resource prefix.
461
+
462
+ A passed-in `ResourceLoader` (for example, one supplied via
463
+ <<resources-resourceloaderaware, `ResourceLoaderAware`>> semantics can be checked whether
464
+ it implements this extended interface too.
465
+
466
+ `PathMatchingResourcePatternResolver` is a standalone implementation that is usable
467
+ outside an `ApplicationContext` and is also used by `ResourceArrayPropertyEditor` for
468
+ populating `Resource[]` bean properties.
469
+
470
+ [NOTE]
471
+ ====
472
+ The default `ResourceLoader` in any standard `ApplicationContext` is in fact an instance
473
+ of `PathMatchingResourcePatternResolver` which implements the `ResourcePatternResolver`
474
+ interface. The same is true for the `ApplicationContext` instance itself which also
475
+ implements the `ResourcePatternResolver` interface and delegates to the default
476
+ `PathMatchingResourcePatternResolver`.
477
+ ====
478
+
479
+
419
480
[[resources-resourceloaderaware]]
420
- == The `ResourceLoaderAware` interface
481
+ == The `ResourceLoaderAware` Interface
421
482
422
483
The `ResourceLoaderAware` interface is a special callback interface which identifies
423
484
components that expect to be provided a `ResourceLoader` reference. The following listing
@@ -628,7 +689,7 @@ javadoc for details on the various constructors.
628
689
629
690
The resource paths in application context constructor values may be simple paths (as
630
691
shown earlier), each of which has a one-to-one mapping to a target `Resource` or,
631
- alternately, may contain the special " classpath*:" prefix or internal Ant-style patterns
692
+ alternately, may contain the special ` classpath*:` prefix or internal Ant-style patterns
632
693
(matched by using Spring's `PathMatcher` utility). Both of the latter are effectively
633
694
wildcards.
634
695
0 commit comments