The common supertype of the interfaces through which the container hands a bean one of its own objects: its bean name, the bean factory, the environment and so on.
A bean implements one of the subinterfaces (BeanNameAware,
BeanFactoryAware, and in the context package EnvironmentAware,
ApplicationContextAware and others), and the container calls its
setter once, after injection and before the init callbacks
(@PostConstruct, afterPropertiesSet). Aware itself has no
methods; it only groups them. Application code rarely needs
these interfaces: injecting the object through the constructor
(BeanFactory, Environment, ApplicationContext) is simpler. They
are for framework classes, and for the rare bean that needs its own
name.
// An audit service that tags its log lines with its own bean name.
@Service()
class Audit implements BeanNameAware {
late String name;
@override
void setBeanName(String name) => this.name = name;
}
Spring (Java):
@Service
class Audit implements BeanNameAware {
String name;
@Override public void setBeanName(String name) { this.name = name; }
}
- 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
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited