public interface BeanFactory
Definition of an interface for bean factories.
Beans defined in configuration files are not directly created, but by so called bean factories. This additional level of indirection provides for high flexibility in the creation process. For instance one implementation of this interface could be very simple and create a new instance of the specified class for each invocation. A different implementation could cache already created beans and ensure that always the same bean of the given class will be returned - this would be an easy mean for creating singleton objects.
The interface itself is quite simple. There is a single method for creating a bean of a given class. All necessary
parameters are obtained from a passed in BeanCreationContext
object. It is also possible (but optional) for a
bean factory to declare the default class of the bean it creates. Then it is not necessary to specify a bean class in
the bean declaration.
Modifier and Type | Method and Description |
---|---|
Object |
createBean(BeanCreationContext bcc)
Creates a bean instance for the given context object.
|
Class<?> |
getDefaultBeanClass()
Gets the default bean class of this bean factory.
|
Object createBean(BeanCreationContext bcc) throws Exception
BeanCreationContext
object. This includes a BeanDeclaration
defining the properties of
the bean. It is up to a concrete implementation how the bean is created and initialized.bcc
- the context object for the bean to be createdException
- if an error occurs (the helper classes for creating beans will catch this generic exception and
wrap it in a configuration exception)Class<?> getDefaultBeanClass()
Copyright © 2001–2022 The Apache Software Foundation. All rights reserved.