Implemented by a bean that wants the application context handed to it through a method call.
The usual way is to inject ApplicationContext through the
constructor. This callback is for beans that cannot take it as a
parameter, for example a base class shared by many beans whose
constructors you do not want to change. The context calls
setApplicationContext once, after the bean's dependencies are
injected and before its init callbacks (@PostConstruct).
// Looks beans up by name at runtime, e.g. a handler chosen by a
// message type.
@Component()
class BeanLocator implements ApplicationContextAware {
late ApplicationContext context;
@override
void setApplicationContext(ApplicationContext applicationContext) =>
context = applicationContext;
}
Spring (Java):
@Component
class BeanLocator implements ApplicationContextAware {
public void setApplicationContext(ApplicationContext ctx) { ... }
}
- Implemented types
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
-
setApplicationContext(
ApplicationContext applicationContext) → void - Receives the context that created the bean; called once, after injection and before the init callbacks.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited