The registry behind classpath: locations: the files of
lib/resources/ of the application and of its dependencies.
Dart has no classpath, so the generator embeds every file of a
package's lib/resources/ into its generated module, and the files are
registered here when the module is created. That is how
application.yml, message bundles and templates are found on every
platform. A path that is not embedded (a file added while developing
without regenerating) is read from lib/resources/<path> on disk.
Directories added with addDirectory come first, like
src/test/resources before src/main/resources on a test classpath: a
file there shadows the embedded file with the same path. A path whose
.. segments climb above lib/resources/ (classpath:../../secret)
finds nothing, as Java's class loader refuses such a name: resolve
gives a resource that does not exist.
Applications only write locations (classpath:templates/mail.txt);
resource loaders call this class. Code calls it directly in tests, to
add a directory, or to list the embedded files.
// Reads lib/resources/banner.txt, embedded or from disk.
final resource =
DefaultResourceLoader().getResource('classpath:banner.txt');
log.info(resource.readAsStringSync());
Spring (Java):
Resource resource = new ClassPathResource("banner.txt");
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
-
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
Static Properties
Static Methods
-
addDirectory(
String directory) → void Function() -
Makes
classpath:look indirectoryon disk before the embedded files, until the returned function is called. The most recently added directory comes first.spring_boot_starter_testuses it fortest/resources/, so test config files win over packaged ones. -
migrate(
String location) → String -
locationwith the former prefixclasspath:(orclasspath*:) replaced byresources:(resources*:), after a warning naming the new prefix, once per location. Anything else, anoptional:prefix included, is returned as it is. -
migrateOptional(
String location) → String -
locationafteroptional:-aware migrate:optional:classpath:xgivesoptional:resources:x. -
normalize(
String path) → String? -
pathrelative tolib/resources/(withoutclasspath:): a leading/removed,\read as/,.and empty segments dropped,..resolved (/config/./app.propertiesgivesconfig/app.properties).nullwhen..climbs above the root: nothing there is on the classpath. -
registerAll(
Map< String, EmbeddedResource> resources, {String? owner}) → void -
Registers embedded files, keyed by their path under
lib/resources/. Generated modules call it; applications do not. -
resetLegacyWarnings(
) → void - Forgets the locations already warned about, for tests.
-
resolve(
String path) → Resource -
The resource for
resources:<path>(or the formerclasspath:) or a plainpath: a file of an added directory when it exists there, otherwise the embedded file, otherwise the file under directory (which may not exist). A path that climbs above the root with..gives a resource that does not exist and cannot be read; so doescreateRelativeof an embedded file. A file read from disk is a FileSystemResource, whosecreateRelativeis a file's. -
resolveEmbedded(
String path) → Resource -
The resource for
path, ignoring the added directories: the embedded file, or else the file under directory; nothing for a path that climbs above the root, as in resolve.
Constants
- allPrefix → const String
-
The prefix that searches every root,
resources*:(Spring'sclasspath*:). - directory → const String
-
The directory read from disk for paths that are not embedded:
lib/resources, relative to the working directory. - legacyAllPrefix → const String
-
The former prefix of the search over every root,
classpath*:. - legacyPrefix → const String
-
The former prefix,
classpath:, still read in 0.6.2 with a warning and refused in the next minor release. - prefix → const String
-
The location prefix,
resources:.