ConditionalOnResource class
Registers a bean only when every one of some files exists.
Useful for a bean that reads a file which only some installations
have, such as a certificate or a template, so the application starts
without it elsewhere. The locations are resolved like any resource
(classpath: is lib/resources/, file: the file system), after
${...} placeholders are replaced.
// TLS only where the operators mounted a certificate.
@Bean()
@ConditionalOnResource(['file:./config/tls/cert.pem'])
TlsSettings tls() => TlsSettings.fromDirectory('./config/tls');
Spring (Java):
@ConditionalOnResource(resources = "file:./config/tls/cert.pem").
- Implemented types
Constructors
-
ConditionalOnResource(List<
String> resources) -
Requires every location of
resourcesto exist.const
Properties
Methods
-
matches(
ConditionContext context) → bool -
Whether the annotated bean should be registered;
contextgives access to the configuration and the definitions registered so far.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited