BeanResolver class abstract interface

Looks up the object an @name (or &name) reference stands for.

Bean references let an expression use a named object of the application, such as @mailer.defaultSender. In @Value('#{...}') the framework sets a BeanFactoryResolver for you. Set one on a StandardEvaluationContext yourself when your own expressions should see beans, or implement this interface to serve names from any registry. Without a resolver, @name fails with noBeanResolverRegistered (EL1057E); a SimpleEvaluationContext never has one.

// Named objects from a map, for tests or a small rule engine.
final class MapBeanResolver implements BeanResolver {
  MapBeanResolver(this.beans);
  final Map<String, Object> beans;

  @override
  Object? resolve(EvaluationContext context, String beanName) =>
      beans[beanName] ?? (throw AccessException('No bean $beanName'));
}

final context = StandardEvaluationContext()
  ..beanResolver = MapBeanResolver({'clock': clock});
SpelExpressionParser().parseExpression('@clock').getValue(context);

Spring (Java):

context.setBeanResolver(new BeanFactoryResolver(beanFactory));
parser.parseExpression("@clock").getValue(context);

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
resolve(EvaluationContext context, String beanName) → Object?
The object named beanName; for &name the name arrives with its & (the factory bean itself rather than its product).
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited