A ResourceLoader that also finds all resources matching a pattern
with wildcards, such as classpath:templates/*.html or
file:config/**/*.properties.
Use it to load every file of a kind without listing them: all
templates, all seed data files, all message bundles. The application
context is one, so a constructor parameter of type
ResourcePatternResolver receives it.
@Component()
class Templates {
Templates(this.resources);
final ResourcePatternResolver resources; // the application context
// Every mail template shipped in lib/resources/mail/.
List<Resource> all() => resources.getResources('classpath:mail/*.txt');
}
Spring (Java):
@Component
class Templates {
private final ResourcePatternResolver resources;
Templates(ResourcePatternResolver resources) {
this.resources = resources;
}
Resource[] all() throws IOException {
return resources.getResources("classpath:mail/*.txt");
}
}
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
getResource(
String location) → Resource -
The resource at
location. Nothing is read yet, and the resource may not exist: check Resource.exists before reading when it may be missing. Never returnsnull; an unknown prefix gives a resource that does not exist.inherited -
getResources(
String locationPattern) → List< Resource> -
All resources matching
locationPattern, possibly none. A location without wildcards gives that one resource when it exists. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited