Skip to content

Commit e475151

Browse files
committedJun 29, 2023
Additional notes on module access via ClassPathResource
See gh-28507
·
v7.0.0-M9v6.1.0-M2
1 parent bd7e2d2 commit e475151

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ public ClassPathResource(String path, @Nullable ClassLoader classLoader) {
100100
* the class path via a leading slash.
101101
* <p>If the supplied {@code Class} is {@code null}, the default class
102102
* loader will be used for loading the resource.
103+
* <p>This is also useful for resource access within the module system,
104+
* loading a resource from the containing module of a given {@code Class}.
105+
* See {@link ModuleResource} and its javadoc.
103106
* @param path relative or absolute path within the class path
104107
* @param clazz the class to load resources with
105108
* @see ClassUtils#getDefaultClassLoader()
109+
* @see ModuleResource
106110
*/
107111
public ClassPathResource(String path, @Nullable Class<?> clazz) {
108112
Assert.notNull(path, "Path must not be null");
@@ -257,7 +261,7 @@ public String getFilename() {
257261
*/
258262
@Override
259263
public String getDescription() {
260-
return "class path resource [" + this.absolutePath + ']';
264+
return "class path resource [" + this.absolutePath + "]";
261265
}
262266

263267

@@ -272,7 +276,7 @@ public boolean equals(@Nullable Object obj) {
272276
if (this == obj) {
273277
return true;
274278
}
275-
return ((obj instanceof ClassPathResource that) &&
279+
return (obj instanceof ClassPathResource that &&
276280
this.absolutePath.equals(that.absolutePath) &&
277281
ObjectUtils.nullSafeEquals(getClassLoader(), that.getClassLoader()));
278282
}

‎spring-core/src/main/java/org/springframework/core/io/ModuleResource.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
* {@link Resource} implementation for {@link java.lang.Module} resolution,
2929
* performing {@link #getInputStream()} access via {@link Module#getResourceAsStream}.
3030
*
31-
* <p>Alternatively, consider accessing resources in a module path layout
32-
* via {@link ClassPathResource} for exported resources, or specifically
33-
* via {@link ClassPathResource#ClassPathResource(String, Class)}
34-
* for local resolution within the containing module of a specific class.
31+
* <p>Alternatively, consider accessing resources in a module path layout via
32+
* @link ClassPathResource} for exported resources, or specifically relative to
33+
* a {@code Class} via {@link ClassPathResource#ClassPathResource(String, Class)}
34+
* for local resolution within the containing module of that specific class.
3535
*
3636
* @author Juergen Hoeller
37+
* @author Sam Brannen
3738
* @since 6.1
3839
* @see Module#getResourceAsStream
3940
* @see ClassPathResource

0 commit comments

Comments
 (0)
Please sign in to comment.