public class ResourceLoaderResourceResolver extends java.lang.Object implements org.springframework.context.ResourceLoaderAware, ResourceResolver
ApplicationContext
,
ResourceLoaderAware
,
ClassPathResource
,
DefaultResourceLoader
,
Resource
,
ResourceLoader
,
ResourceResolver
Constructor and Description |
---|
ResourceLoaderResourceResolver() |
Modifier and Type | Method and Description |
---|---|
java.util.Optional<java.lang.ClassLoader> |
getClassLoader()
Gets an
Optional ClassLoader used by the ResourceLoader to resolve and load
Resources located on the classpath. |
protected org.springframework.core.io.ResourceLoader |
getResourceLoader()
Returns a reference to the configured
ResourceLoader used to load Resources . |
protected boolean |
isQualified(org.springframework.core.io.Resource resource)
Determines whether the
Resource is a qualified Resource . |
protected org.springframework.core.io.Resource |
newResource(java.lang.String location)
Constructs a new
Resource handle at the given location . |
protected org.springframework.core.io.ResourceLoader |
newResourceLoader()
Constructs a new, default instance of
ResourceLoader to load Resources . |
protected org.springframework.core.io.Resource |
onMissingResource(org.springframework.core.io.Resource resource,
java.lang.String location)
Action to perform when the
Resource identified at the specified location is missing,
or was not qualified . |
protected org.springframework.core.io.Resource |
postProcess(org.springframework.core.io.Resource resource)
Method used by subclasses to process the loaded
Resource as determined by
the ResourceLoader . |
java.util.Optional<org.springframework.core.io.Resource> |
resolve(java.lang.String location)
Tries to resolve a
Resource at the given location using a Spring ResourceLoader ,
such as a Spring ApplicationContext . |
void |
setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
require
public java.util.Optional<java.lang.ClassLoader> getClassLoader()
Optional
ClassLoader
used by the ResourceLoader
to resolve and load
Resources
located on the classpath.
Returns the ClassLoader
from the configured ResourceLoader
,
if present. Otherwise, returns a ClassLoader
determined by ClassUtils.getDefaultClassLoader()
,
which first tries to return the Thread.getContextClassLoader()
, then Class.getClassLoader()
,
and finally, ClassLoader.getSystemClassLoader()
.getClassLoader
in interface ResourceResolver
Optional
ClassLoader
to resolve and load Resources
.ResourceLoader.getClassLoader()
,
ClassLoader
,
Optional
public void setResourceLoader(@Nullable org.springframework.core.io.ResourceLoader resourceLoader)
setResourceLoader
in interface org.springframework.context.ResourceLoaderAware
resourceLoader
- ResourceLoader
used to resolve and load Resources
.ResourceLoader
@NonNull protected org.springframework.core.io.ResourceLoader getResourceLoader()
ResourceLoader
used to load Resources
.
If a ResourceLoader
was not explicitly configured, then a default ResourceLoader
using a default ClassLoader
is provided.ResourceLoader
; never null.ResourceLoader
,
newResourceLoader()
@NonNull protected org.springframework.core.io.ResourceLoader newResourceLoader()
ResourceLoader
to load Resources
.
Specifically, creates a standalone DefaultResourceLoader
initialized with a default
ClassLoader
as determined by getClassLoader()
.ResourceLoader
.ResourceLoader
@NonNull protected org.springframework.core.io.Resource newResource(@NonNull java.lang.String location)
Resource
handle at the given location
.
By default, a ClassPathResource
is constructed.location
- location
of the new Resource
; must not be null.Resource
handle at the given location
.java.lang.IllegalArgumentException
- if location
is not specified.Resource
protected boolean isQualified(@Nullable org.springframework.core.io.Resource resource)
Resource
is a qualified Resource
.
Qualifications are determined by the application Requirements and Use Case (UC) at time of resolution.
For example, it maybe that the Resource
must exist
to qualify, or that
the Resource
must have a valid protocol, path and name.
This default implementation requires the target Resource
to not be null.resource
- Resource
to qualify.Resource
is qualified.Resource
@Nullable protected org.springframework.core.io.Resource onMissingResource(@Nullable org.springframework.core.io.Resource resource, @NonNull java.lang.String location)
Resource
identified at the specified location
is missing,
or was not qualified
.resource
- missing Resource
.location
- String
containing the location identifying the missing Resource
.Resource
, possibly. Alternatively, this method may throw
a ResourceNotFoundException
.ResourceNotFoundException
- if the Resource
cannot be found at the specified location
.isQualified(Resource)
protected org.springframework.core.io.Resource postProcess(org.springframework.core.io.Resource resource)
Resource
as determined by
the ResourceLoader
.resource
- Resource
to post-process.Resource
.Resource
public java.util.Optional<org.springframework.core.io.Resource> resolve(@NonNull java.lang.String location)
Resource
at the given location
using a Spring ResourceLoader
,
such as a Spring ApplicationContext
.
The targeted, identified Resource
can be further qualified
by subclasses
based on application requirements or use case (UC).
In the event that a Resource
cannot be identified at the given location
, then applications
have 1 last opportunity to handle the missing Resource
event, and either return a different or default
Resource
or throw a ResourceNotFoundException
.resolve
in interface ResourceResolver
location
- location
identifying the Resource
to resolve;
must not be null.Optional
Resource
handle for the given location
.java.lang.IllegalArgumentException
- if location
is not specified.Resource
,
isQualified(Resource)
,
onMissingResource(Resource, String)
,
postProcess(Resource)
,
Optional