Interface BeanFactoryLocator
- All Known Implementing Classes:
ContextJndiBeanFactoryLocator
,ContextSingletonBeanFactoryLocator
,SingletonBeanFactoryLocator
public interface BeanFactoryLocator
Defines a contract for the lookup, use, and release of aBeanFactory
, or aBeanFactory
subclass such as anApplicationContext
.Where this interface is implemented as a singleton class such as
SingletonBeanFactoryLocator
, the Spring team strongly suggests that it be used sparingly and with caution. By far the vast majority of the code inside an application is best written in a Dependency Injection style, where that code is served out of aBeanFactory
/ApplicationContext
container, and has its own dependencies supplied by the container when it is created. However, even such a singleton implementation sometimes has its use in the small glue layers of code that is sometimes needed to tie other code together. For example, third party code may try to construct new objects directly, without the ability to force it to get these objects out of aBeanFactory
. If the object constructed by the third party code is just a small stub or proxy, which then uses an implementation of this class to get aBeanFactory
from which it gets the real object, to which it delegates, then proper Dependency Injection has been achieved.As another example, in a complex J2EE app with multiple layers, with each layer having its own
ApplicationContext
definition (in a hierarchy), a class likeSingletonBeanFactoryLocator
may be used to demand load these contexts.- Author:
- Colin Sampaleanu
- See Also:
BeanFactory
,DefaultLocatorFactory
,ApplicationContext
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description BeanFactoryReference
useBeanFactory(String factoryKey)
Use theBeanFactory
(or derived interface such asApplicationContext
) specified by thefactoryKey
parameter.
Method Detail
useBeanFactory
BeanFactoryReference useBeanFactory(String factoryKey) throws BeansException
Use theBeanFactory
(or derived interface such asApplicationContext
) specified by thefactoryKey
parameter.The definition is possibly loaded/created as needed.
- Parameters:
factoryKey
- a resource name specifying whichBeanFactory
theBeanFactoryLocator
must return for usage. The actual meaning of the resource name is specific to the implementation ofBeanFactoryLocator
.- Returns:
- the
BeanFactory
instance, wrapped as aBeanFactoryReference
object - Throws:
BeansException
- if there is an error loading or accessing theBeanFactory