A bean that is handed the bean factory that created it, so it can look up other beans by itself while it runs.
Use it when the beans you need are only known at run time (by a name
read from configuration, say). Injecting BeanFactory or an
ObjectProvider<T> through the constructor does the same and is
usually simpler; this interface is mostly for framework classes.
// Plugins are beans; which one runs is decided by name at run time.
@Component()
class PluginLoader implements BeanFactoryAware {
late BeanFactory factory;
@override
void setBeanFactory(BeanFactory beanFactory) => factory = beanFactory;
Plugin load(String name) => factory.getBeanByName(name) as Plugin;
}
Spring (Java):
@Component
class PluginLoader implements BeanFactoryAware {
BeanFactory factory;
@Override public void setBeanFactory(BeanFactory beanFactory) {
factory = beanFactory;
}
Plugin load(String name) { return (Plugin) factory.getBean(name); }
}
- Implemented types
- Implementers
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
-
setBeanFactory(
BeanFactory beanFactory) → void - Receives the factory that holds the bean. Called once, after injection and after BeanNameAware.setBeanName.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited