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 resources to exist.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
resources → List<String>
The resource locations that must exist (classpath:..., file:...); they may contain ${...} placeholders.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

matches(ConditionContext context) → bool
Whether the annotated bean should be registered; context gives 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