
# Resources

A resource is a piece of content the application reads, wherever it lives, named by a location string such as `resources:mail.txt`.

## Why use it

Code that reads a template, a data file or a config file should not care where the file is. With resources, the location string decides: `resources:` (the files of `lib/resources/`), `file:`, `http:` / `https:`, `package:`, or a prefix of your own. The code only reads.

`lib/resources/` plays the role of the Java classpath. The generator embeds its files, so `resources:...` works in `dart run`, AOT executables, Flutter and the web, without asset declarations.

You do not need resources to read configuration values: use [@Value](../config/value.md) or the [Environment](../config/environment.md) for that.

## Example

```dart
import 'package:spring_core_dart/spring_core_dart.dart';

@Service()
class WelcomeLetter {
  // Resolved by the context's resource loader, so custom protocols and
  // asset loaders apply.
  WelcomeLetter(@Value('resources:templates/welcome.txt') this.template);

  final Resource template;

  Future<String> text() => template.readAsString();
}
```

## Pages

- [Resource and ResourceLoader](resource.md): the `Resource` interface, location prefixes, `ResourceLoader`, `ProtocolResolver` and resource patterns.
- [AntPathMatcher](path-matcher.md): Ant-style patterns (`?`, `*`, `**`, `{name}`) used by resource patterns and `@PropertySource`.

## See also

- [@PropertySource](../config/property-source.md)
- [Messages](../messages/index.md)
- [Beans](../beans/index.md)
