Skip to content

Commit ac58614

Browse files
committed
Polish Resources section of the reference manual
See gh-26447
1 parent 4ebd8d7 commit ac58614

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/docs/asciidoc/core/core-resources.adoc

+26-25
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,12 @@ application components instead of `ResourceLoader`.
465465
== Resources as Dependencies
466466

467467
If the bean itself is going to determine and supply the resource path through some sort
468-
of dynamic process, it probably makes sense for the bean to use the `ResourceLoader`
469-
interface to load resources. For example, consider the loading of a template of some
470-
sort, where the specific resource that is needed depends on the role of the user. If the
471-
resources are static, it makes sense to eliminate the use of the `ResourceLoader`
472-
interface completely, have the bean expose the `Resource` properties it needs,
473-
and expect them to be injected into it.
468+
of dynamic process, it probably makes sense for the bean to use the `ResourceLoader` or
469+
`ResourcePatternResolver` interface to load resources. For example, consider the loading
470+
of a template of some sort, where the specific resource that is needed depends on the
471+
role of the user. If the resources are static, it makes sense to eliminate the use of the
472+
`ResourceLoader` interface (or `ResourcePatternResolver` interface) completely, have the
473+
bean expose the `Resource` properties it needs, and expect them to be injected into it.
474474

475475
What makes it trivial to then inject these properties is that all application contexts
476476
register and use a special JavaBeans `PropertyEditor`, which can convert `String` paths
@@ -484,14 +484,14 @@ be configured with a simple string for that resource, as the following example s
484484
</bean>
485485
----
486486

487-
Note that the resource path has no prefix. Consequently, because the application context itself is
488-
going to be used as the `ResourceLoader`, the resource itself is loaded through a
489-
`ClassPathResource`, a `FileSystemResource`, or a `ServletContextResource`,
490-
depending on the exact type of the context.
487+
Note that the resource path has no prefix. Consequently, because the application context
488+
itself is going to be used as the `ResourceLoader`, the resource is loaded through a
489+
`ClassPathResource`, a `FileSystemResource`, or a `ServletContextResource`, depending on
490+
the exact type of the application context.
491491

492-
If you need to force a specific `Resource` type to be used, you can use a prefix.
493-
The following two examples show how to force a `ClassPathResource` and a
494-
`UrlResource` (the latter being used to access a filesystem file):
492+
If you need to force a specific `Resource` type to be used, you can use a prefix. The
493+
following two examples show how to force a `ClassPathResource` and a `UrlResource` (the
494+
latter being used to access a file in the filesystem):
495495

496496
[source,xml,indent=0,subs="verbatim,quotes"]
497497
----
@@ -552,12 +552,12 @@ used. However, consider the following example, which creates a `FileSystemXmlApp
552552
val ctx = FileSystemXmlApplicationContext("conf/appContext.xml")
553553
----
554554

555-
Now the bean definition is loaded from a filesystem location (in this case, relative to
555+
Now the bean definitions are loaded from a filesystem location (in this case, relative to
556556
the current working directory).
557557

558558
Note that the use of the special `classpath` prefix or a standard URL prefix on the
559-
location path overrides the default type of `Resource` created to load the definition.
560-
Consider the following example:
559+
location path overrides the default type of `Resource` created to load the bean
560+
definitions. Consider the following example:
561561

562562
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
563563
.Java
@@ -663,11 +663,11 @@ contents of the jar file to resolve the wildcards.
663663
[[resources-app-ctx-portability]]
664664
===== Implications on Portability
665665

666-
If the specified path is already a file URL (either implicitly because the base
666+
If the specified path is already a `file` URL (either implicitly because the base
667667
`ResourceLoader` is a filesystem one or explicitly), wildcarding is guaranteed to
668668
work in a completely portable fashion.
669669

670-
If the specified path is a classpath location, the resolver must obtain the last
670+
If the specified path is a `classpath` location, the resolver must obtain the last
671671
non-wildcard path segment URL by making a `Classloader.getResource()` call. Since this
672672
is just a node of the path (not the file at the end), it is actually undefined (in the
673673
`ClassLoader` javadoc) exactly what sort of a URL is returned in this case. In practice,
@@ -754,7 +754,7 @@ avoiding the aforementioned portability problems with searching the jar file roo
754754
====
755755

756756
Ant-style patterns with `classpath:` resources are not guaranteed to find matching
757-
resources if the root package to search is available in multiple class path locations.
757+
resources if the root package to search is available in multiple classpath locations.
758758
Consider the following example of a resource location:
759759

760760
[literal,subs="verbatim,quotes"]
@@ -769,12 +769,13 @@ Now consider an Ant-style path that someone might use to try to find that file:
769769
classpath:com/mycompany/**/service-context.xml
770770
----
771771

772-
Such a resource may be in only one location, but when a path such as the preceding example
773-
is used to try to resolve it, the resolver works off the (first) URL returned by
774-
`getResource("com/mycompany");`. If this base package node exists in multiple
775-
`ClassLoader` locations, the actual end resource may not be there. Therefore, in such a case
776-
you should prefer using `classpath*:` with the same Ant-style pattern, which
777-
searches all class path locations that contain the root package.
772+
Such a resource may exist in only one location in the classpath, but when a path such as
773+
the preceding example is used to try to resolve it, the resolver works off the (first)
774+
URL returned by `getResource("com/mycompany");`. If this base package node exists in
775+
multiple `ClassLoader` locations, the desired resource may not exist in the first
776+
location found. Therefore, in such cases you should prefer using `classpath*:` with the
777+
same Ant-style pattern, which searches all classpath locations that contain the
778+
`com.mycompany` base package: `classpath*:com/mycompany/**/service-context.xml`.
778779

779780

780781

0 commit comments

Comments
 (0)