Additional notes on module access via ClassPathResource
See gh-28507
This commit is contained in:
@@ -100,9 +100,13 @@ public class ClassPathResource extends AbstractFileResolvingResource {
|
||||
* the class path via a leading slash.
|
||||
* <p>If the supplied {@code Class} is {@code null}, the default class
|
||||
* loader will be used for loading the resource.
|
||||
* <p>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()));
|
||||
}
|
||||
|
||||
@@ -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}.
|
||||
*
|
||||
* <p>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.
|
||||
* <p>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
|
||||
|
||||
Reference in New Issue
Block a user