public class

AnnotationConfigWebApplicationContext

extends AbstractRefreshableWebApplicationContext
java.lang.Object
   ↳ org.springframework.core.io.DefaultResourceLoader
     ↳ org.springframework.context.support.AbstractApplicationContext
       ↳ org.springframework.context.support.AbstractRefreshableApplicationContext
         ↳ org.springframework.context.support.AbstractRefreshableConfigApplicationContext
           ↳ org.springframework.web.context.support.AbstractRefreshableWebApplicationContext
             ↳ org.springframework.web.context.support.AnnotationConfigWebApplicationContext

Class Overview

WebApplicationContext implementation which accepts annotated classes as input - in particular @Configuration-annotated classes, but also plain @Components and JSR-330 compliant classes using javax.inject annotations. Allows for registering classes one by one (specifying class names as config location) as well as for classpath scanning (specifying base packages as config location).

This is essentially the equivalent of AnnotationConfigApplicationContext for a web environment.

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.

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.

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.

Summary

[Expand]
Inherited Constants
From class org.springframework.context.support.AbstractApplicationContext
From interface org.springframework.beans.factory.BeanFactory
From interface org.springframework.context.ConfigurableApplicationContext
From interface org.springframework.core.io.ResourceLoader
From interface org.springframework.core.io.support.ResourcePatternResolver
From interface org.springframework.web.context.ConfigurableWebApplicationContext
From interface org.springframework.web.context.WebApplicationContext
[Expand]
Inherited Fields
From class org.springframework.context.support.AbstractApplicationContext
From interface org.springframework.web.context.ConfigurableWebApplicationContext
From interface org.springframework.web.context.WebApplicationContext
Public Constructors
AnnotationConfigWebApplicationContext()
Protected Methods
BeanNameGenerator getBeanNameGenerator()
ScopeMetadataResolver getScopeMetadataResolver()
void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
Register a BeanDefinition for each class specified by getConfigLocations(), or scan each specified package for annotated classes.
[Expand]
Inherited Methods
From class org.springframework.web.context.support.AbstractRefreshableWebApplicationContext
From class org.springframework.context.support.AbstractRefreshableConfigApplicationContext
From class org.springframework.context.support.AbstractRefreshableApplicationContext
From class org.springframework.context.support.AbstractApplicationContext
From class org.springframework.core.io.DefaultResourceLoader
From class java.lang.Object
From interface org.springframework.beans.factory.BeanFactory
From interface org.springframework.beans.factory.BeanNameAware
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.beans.factory.HierarchicalBeanFactory
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.beans.factory.ListableBeanFactory
From interface org.springframework.context.ApplicationContext
From interface org.springframework.context.ApplicationEventPublisher
From interface org.springframework.context.ConfigurableApplicationContext
From interface org.springframework.context.Lifecycle
From interface org.springframework.context.MessageSource
From interface org.springframework.core.env.EnvironmentCapable
From interface org.springframework.core.io.ResourceLoader
From interface org.springframework.core.io.support.ResourcePatternResolver
From interface org.springframework.ui.context.ThemeSource
From interface org.springframework.web.context.ConfigurableWebApplicationContext
From interface org.springframework.web.context.WebApplicationContext

Public Constructors

public AnnotationConfigWebApplicationContext ()

Protected Methods

protected void loadBeanDefinitions (DefaultListableBeanFactory beanFactory)

Register a BeanDefinition for each class specified by getConfigLocations(), or scan each specified package for annotated classes. Enables the default set of annotation configuration post processors, such that @Autowired, @Required, and associated annotations can be used.

Configuration class bean definitions are registered with generated bean definition names unless the value attribute is provided to the stereotype annotation.

Parameters
beanFactory the bean factory to load bean definitions into