diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index 69cb22e4ad..72928a94be 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -100,9 +100,13 @@ public class ClassPathResource extends AbstractFileResolvingResource { * the class path via a leading slash. *
If the supplied {@code Class} is {@code null}, the default class * loader will be used for loading the resource. + *
This is also useful for resource access within the module system, + * loading a resource from the containing module of a given {@code Class}. + * See {@link ModuleResource} and its javadoc. * @param path relative or absolute path within the class path * @param clazz the class to load resources with * @see ClassUtils#getDefaultClassLoader() + * @see ModuleResource */ public ClassPathResource(String path, @Nullable Class> clazz) { Assert.notNull(path, "Path must not be null"); @@ -257,7 +261,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { */ @Override public String getDescription() { - return "class path resource [" + this.absolutePath + ']'; + return "class path resource [" + this.absolutePath + "]"; } @@ -272,7 +276,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { if (this == obj) { return true; } - return ((obj instanceof ClassPathResource that) && + return (obj instanceof ClassPathResource that && this.absolutePath.equals(that.absolutePath) && ObjectUtils.nullSafeEquals(getClassLoader(), that.getClassLoader())); } diff --git a/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java b/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java index 6ba2083cb2..3c2e2aeb62 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java @@ -28,12 +28,13 @@ import org.springframework.util.StringUtils; * {@link Resource} implementation for {@link java.lang.Module} resolution, * performing {@link #getInputStream()} access via {@link Module#getResourceAsStream}. * - *
Alternatively, consider accessing resources in a module path layout - * via {@link ClassPathResource} for exported resources, or specifically - * via {@link ClassPathResource#ClassPathResource(String, Class)} - * for local resolution within the containing module of a specific class. + *
Alternatively, consider accessing resources in a module path layout via + * @link ClassPathResource} for exported resources, or specifically relative to + * a {@code Class} via {@link ClassPathResource#ClassPathResource(String, Class)} + * for local resolution within the containing module of that specific class. * * @author Juergen Hoeller + * @author Sam Brannen * @since 6.1 * @see Module#getResourceAsStream * @see ClassPathResource