org.springframework.beans.factory.support.DefaultListableBeanFactory
instance and does not assume a specific bean definition format. Implements
the org.springframework.beans.factory.support.BeanDefinitionRegistry
interface in order to allow for applying any bean definition readers to it.
Typical usage is to register a variety of bean definitions via the
org.
interface and then call refresh() to initialize those beans
with application context semantics (handling
org., auto-detecting
BeanFactoryPostProcessors,
etc).
In contrast to other ApplicationContext implementations that create a new
internal BeanFactory instance for each refresh, the internal BeanFactory of
this context is available right from the start, to be able to register bean
definitions on it. refresh() may only be called once.
This ApplicationContext implementation is suitable for Ahead of Time
processing, using refreshForAotProcessing as an alternative to the
regular refresh().
Usage example:
GenericApplicationContext ctx = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
PropertiesBeanDefinitionReader propReader = new PropertiesBeanDefinitionReader(ctx);
propReader.loadBeanDefinitions(new ClassPathResource("otherBeans.properties"));
ctx.refresh();
MyBean myBean = (MyBean) ctx.getBean("myBean");
...
For the typical case of XML bean definitions, you may also use
ClassPathXmlApplicationContext or FileSystemXmlApplicationContext,
which are easier to set up - but less flexible, since you can just use standard
resource locations for XML bean definitions, rather than mixing arbitrary bean
definition formats. For a custom application context implementation supposed to
read a specific bean definition format in a refreshable manner, consider
deriving from the AbstractRefreshableApplicationContext base class.
registerBeanDefinition, refresh(), org.springframework.beans.factory.xml.XmlBeanDefinitionReader , org.springframework.beans.factory.support.PropertiesBeanDefinitionReader
| Modifier and Type | Class and Description |
|---|---|
| private static class | GenericApplicationContext.ClassDerivedBeanDefinition
|
| Modifier and Type | Field and Description |
|---|---|
| private final DefaultListableBeanFactory | |
| private boolean | |
| private final AtomicBoolean | |
| private ResourceLoader |
| Access | Constructor and Description |
|---|---|
| public | |
| public | GenericApplicationContext(DefaultListableBeanFactory
the DefaultListableBeanFactory instance to use for this context beanFactory)Create a new GenericApplicationContext with the given DefaultListableBeanFactory. |
| public | GenericApplicationContext(ApplicationContext
the parent application context parent)Create a new GenericApplicationContext with the given parent. |
| public | GenericApplicationContext(DefaultListableBeanFactory
the DefaultListableBeanFactory instance to use for this context beanFactory, ApplicationContext the parent application context parent)Create a new GenericApplicationContext with the given DefaultListableBeanFactory. |
| Modifier and Type | Method and Description |
|---|---|
| protected void | cancelRefresh(Throwable
the exception that led to the cancellation ex)Overrides org. active flag
after an exception got thrown.
|
| protected final void | closeBeanFactory()
Implements abstract org. |
| public AutowireCapableBeanFactory | getAutowireCapableBeanFactory()
Overrides org. Implements org. |
| public BeanDefinition | getBeanDefinition(String
name of the bean to find a definition for beanName)Implements org. |
| public final ConfigurableListableBeanFactory | getBeanFactory()
Implements abstract org. Implements org. |
| public ClassLoader | getClassLoader()
Overrides org. Implements org. ClassLoader used by this ResourceLoader.
|
| public final DefaultListableBeanFactory | Returns: the internal bean factory (as DefaultListableBeanFactory)Return the underlying bean factory of this context, available for registering bean definitions. |
| public Resource | getResource(String
the resource location location)Overrides org. Implements org. ResourceLoader if set,
falling back to the default superclass behavior otherwise.
|
| public Resource[] | getResources(String
the location pattern to resolve locationPattern)Overrides org. Implements org. |
| public boolean | isAlias(String
the name to check beanName)Implements org. |
| public boolean | isBeanDefinitionOverridable(String
the name to check beanName)Overrides default org. registerBeanDefinition would successfully return
against an existing definition of the same name.
|
| public boolean | isBeanNameInUse(String
the name to check beanName)Implements org. |
| private void | preDetermineBeanTypes(RuntimeHints runtimeHints)
Pre-determine bean types in order to trigger early proxy class creation. |
| protected final void | refreshBeanFactory()
Implements abstract org. |
| public void | refreshForAotProcessing(RuntimeHints
the runtime hints runtimeHints)Load or refresh the persistent representation of the configuration up to a point where the underlying bean factory is ready to create bean instances. |
| public void | registerAlias(String
the canonical name beanName, String the alias to be registered alias)Implements org. |
| public <T> void | registerBean(Class<T>
the class of the bean beanClass, Object... custom argument values to be fed into Spring's
constructor resolution algorithm, resolving either all arguments or just
specific ones, with the rest to be resolved through regular autowiring
(may be constructorArgs)null or empty)Register a bean from the given bean class, optionally providing explicit constructor arguments for consideration in the autowiring process. |
| public <T> void | registerBean(String
the name of the bean (may be beanName, Class<T> null)the class of the bean beanClass, Object... custom argument values to be fed into Spring's
constructor resolution algorithm, resolving either all arguments or just
specific ones, with the rest to be resolved through regular autowiring
(may be constructorArgs)null or empty)Register a bean from the given bean class, optionally providing explicit constructor arguments for consideration in the autowiring process. |
| public final <T> void | registerBean(Class<T>
the class of the bean (resolving a public constructor
to be autowired, possibly simply the default constructor) beanClass, BeanDefinitionCustomizer... one or more callbacks for customizing the factory's
customizers)BeanDefinition, e.g. setting a lazy-init or primary flagRegister a bean from the given bean class, optionally customizing its bean definition metadata (typically declared as a lambda expression). |
| public final <T> void | registerBean(String
the name of the bean (may be beanName, Class<T> null)the class of the bean (resolving a public constructor
to be autowired, possibly simply the default constructor) beanClass, BeanDefinitionCustomizer... one or more callbacks for customizing the factory's
customizers)BeanDefinition, e.g. setting a lazy-init or primary flagRegister a bean from the given bean class, optionally customizing its bean definition metadata (typically declared as a lambda expression). |
| public final <T> void | registerBean(Class<T>
the class of the bean beanClass, Supplier<T> a callback for creating an instance of the bean supplier, BeanDefinitionCustomizer... one or more callbacks for customizing the factory's
customizers)BeanDefinition, e.g. setting a lazy-init or primary flagRegister a bean from the given bean class, using the given supplier for obtaining a new instance (typically declared as a lambda expression or method reference), optionally customizing its bean definition metadata (again typically declared as a lambda expression). |
| public <T> void | registerBean(String
the name of the bean (may be beanName, Class<T> null)the class of the bean beanClass, Supplier<T> a callback for creating an instance of the bean (in case
of supplier, BeanDefinitionCustomizer... null, resolving a public constructor to be autowired instead)one or more callbacks for customizing the factory's
customizers)BeanDefinition, e.g. setting a lazy-init or primary flagRegister a bean from the given bean class, using the given supplier for obtaining a new instance (typically declared as a lambda expression or method reference), optionally customizing its bean definition metadata (again typically declared as a lambda expression). |
| public void | registerBeanDefinition(String
the name of the bean instance to register beanName, BeanDefinition definition of the bean instance to register beanDefinition)Implements org. |
| public void | removeAlias(String
the alias to remove alias)Implements org. |
| public void | removeBeanDefinition(String
the name of the bean instance to register beanName)Implements org. |
| public void | setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
Set whether it should be allowed to override bean definitions by registering a different definition with the same name, automatically replacing the former. |
| public void | setAllowCircularReferences(boolean allowCircularReferences)
Set whether to allow circular references between beans - and automatically try to resolve them. |
| public void | setApplicationStartup(ApplicationStartup
the new context event factory applicationStartup)Overrides org. Implements org. ApplicationStartup for this application context.
|
| public void | setClassLoader(ClassLoader classLoader)
Overrides org. Implements org. |
| public void | setParent(ApplicationContext
the parent context parent)Overrides org. Implements org. |
| public void |