Deprecated
as a consequence of AbstractRefreshableWebApplicationContext being deprecated. See corresponding docs for further information.
WebApplicationContext
implementation which accepts component classes as input — in particular
@Configuration
classes, but also plain @Component
classes as well as JSR-330 compliant classes using jakarta.inject annotations.
Allows for registering classes one by one (specifying class names as config locations) as well as via classpath scanning (specifying base packages as config locations).
This is essentially the equivalent of
AnnotationConfigApplicationContext for a web environment. However, in contrast to
AnnotationConfigApplicationContext, this class does not extend
GenericApplicationContext and therefore does not provide some of the convenient
registerBean(...) methods available in a GenericApplicationContext.
If you wish to register annotated component classes with a
GenericApplicationContext in a web environment, you may use a
GenericWebApplicationContext with an
AnnotatedBeanDefinitionReader. See the Javadoc for GenericWebApplicationContext
for details and an example.
To make use of this application context, the "contextClass" context-param for ContextLoader and/or "contextClass" init-param for FrameworkServlet must be set to the fully-qualified name of this class.
This class may also be directly instantiated and injected into Spring's
DispatcherServlet or ContextLoaderListener when using the
WebApplicationInitializer
code-based alternative to web.xml. See its Javadoc for details and usage examples.
Unlike XmlWebApplicationContext, no default configuration class locations
are assumed. Rather, it is a requirement to set the
"contextConfigLocation"
context-param for ContextLoader and/or "contextConfigLocation" init-param for
FrameworkServlet. The param-value may contain both fully-qualified
class names and base packages to scan for components. See loadBeanDefinitions
for exact details on how these locations are processed.
As an alternative to setting the "contextConfigLocation" parameter, users may
implement an ApplicationContextInitializer and set the
"contextInitializerClasses"
context-param / init-param. In such cases, users should favor the refresh()
and scan(String. methods over the setConfigLocation(String)
method, which is primarily for use by ContextLoader.
Note
In case of multiple @Configuration classes, later @Bean
definitions will override ones defined in earlier loaded files. This can be leveraged
to deliberately override certain bean definitions via an extra @Configuration
class.
org.springframework.context.annotation.AnnotationConfigApplicationContext , org.springframework.web.context.support.GenericWebApplicationContext
| Modifier and Type | Field and Description |
|---|---|
| private final Set | |
| private BeanNameGenerator | |
| private final Set | |
| private ScopeMetadataResolver |
| Access | Constructor and Description |
|---|---|
| public |
| basePackages | back to summary |
|---|---|
| private final Set<String> basePackages | |
| beanNameGenerator | back to summary |
|---|---|
| private BeanNameGenerator beanNameGenerator
| |
| componentClasses | back to summary |
|---|---|
| private final Set<Class<?>> componentClasses | |
| scopeMetadataResolver | back to summary |
|---|---|
| private ScopeMetadataResolver scopeMetadataResolver
| |
| AnnotationConfigWebApplicationContext | back to summary |
|---|---|
| public AnnotationConfigWebApplicationContext() | |
| getAnnotatedBeanDefinitionReader | back to summary |
|---|---|
| protected AnnotatedBeanDefinitionReader getAnnotatedBeanDefinitionReader(DefaultListableBeanFactory beanFactory) Build an This should be pre-configured with the
| |
| getBeanNameGenerator | back to summary |
|---|---|
| protected BeanNameGenerator getBeanNameGenerator() Return the custom
| |
| getClassPathBeanDefinitionScanner | back to summary |
|---|---|
| protected ClassPathBeanDefinitionScanner getClassPathBeanDefinitionScanner(DefaultListableBeanFactory beanFactory) Build a This should be pre-configured with the
| |
| getScopeMetadataResolver | back to summary |
|---|---|
| protected ScopeMetadataResolver getScopeMetadataResolver() Return the custom
| |
| loadBeanDefinitions | back to summary |
|---|---|
| protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) Implements abstract org. Register a For any values specified by Enables the default set of annotation configuration post processors, such that
Configuration class bean definitions are registered with generated bean
definition names unless the
| |
| register | back to summary |
|---|---|
| public void register(Class<?>... componentClasses) Implements org. Register one or more component classes to be processed. Note that
| |
| scan | back to summary |
|---|---|
| public void scan(String... basePackages) Implements org. Perform a scan within the specified base packages. Note that
| |
| setBeanNameGenerator | back to summary |
|---|---|
| public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) Set a custom Default is | |
| setScopeMetadataResolver | back to summary |
|---|---|
| public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver) Set a custom Default is an | |