A bean factory with a parent: what it cannot find among its own beans, it looks up in the parent.
A parent lets separate parts of a program share common beans (a database, a clock) while each part keeps beans of its own: the child sees the parent's beans, the parent does not see the child's. Most applications have a single context and never set a parent.
// A feature module gets its own factory on top of the shared one.
final shared = DefaultListableBeanFactory();
final feature = DefaultListableBeanFactory(parentBeanFactory: shared);
feature.containsBean('clock'); // true if the shared factory has it
feature.containsLocalBean('clock'); // false
Spring (Java):
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
child.containsBean("fromParent");
child.containsLocalBean("fromParent");
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- parentBeanFactory → BeanFactory?
-
The factory consulted when a lookup finds nothing here;
nullfor a root factory.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
containsBean(
String name) → bool -
Whether a bean or alias named
nameexists here or in a parent (&nameonly for a factory bean). Creates nothing.inherited -
containsBeanOfType(
Type type, {String? qualifier, bool includeAncestors = true}) → bool -
Whether injecting
typewould find a bean, without creating any.inherited -
containsLocalBean(
String name) → bool -
Whether this factory itself, ignoring the parent, has a bean or alias
named
name(&nameonly for a factory bean). -
findBean<
T extends Object> ({String? qualifier}) → T? -
Like getBean, but returns
nullwhen no bean matches, for a collaborator the caller can do without. Still throwsNoUniqueBeanDefinitionExceptionwhen several match and none wins. Spring:getBeanProvider(T).getIfAvailable().inherited -
getAliases(
String name) → List< String> -
The other names of the bean named
name: its aliases, plus its bean name whennameis itself an alias. Empty when there are none or no bean has that name.inherited -
getBean<
T extends Object> ({String? qualifier}) → T -
The bean of type
T, created if it does not exist yet. Withqualifier, only the bean with that name, alias or@Qualifiervalue.inherited -
getBeanByName(
String name) → Object -
The bean registered under
nameor one of its aliases, created if needed; looks in the parent when the name is not known here.inherited -
getBeanProvider<
T extends Object> ({String? qualifier}) → ObjectProvider< T> -
A handle on the beans of
Tthat creates nothing until it is used.inherited -
getType(
String name) → Type? -
The type of the bean named
name, without creating it: the declared class (or what aSmartInstantiationAwareBeanPostProcessorpredicts), the product type for a factory bean (&name: the factory's class), the runtime type of an object added withregisterSingleton.nullwhen no bean has that name.inherited -
isPrototype(
String name) → bool -
Whether every lookup of the bean named
namecreates a new instance. For aFactoryBean, whether its product is created per lookup (this creates the factory);&nameasks about the factory itself. A bean in a custom scope is neither a singleton nor a prototype. ThrowsNoSuchBeanDefinitionExceptionfor an unknown name.inherited -
isSingleton(
String name) → bool -
Whether the bean named
nameis one shared instance. For aFactoryBean, whether its product is shared (this creates the factory);&nameasks about the factory itself. ThrowsNoSuchBeanDefinitionExceptionfor an unknown name.inherited -
isTypeMatch(
String name, Type type) → bool -
Whether the bean named
namecan be used as atype, judged from the types its definition declares, without creating it.inherited -
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