A typical Spring MVC application will have two contexts: the root context and the servlet context.
The root context is loaded by the ContextLoaderListener
. The ContextLoaderListener
loads the ApplicationContext
and sets it as an attribute in the ServletContext
. This makes it available to other Servlet
, Filter
, and XxxListener
instances.
The servlet context is another ApplicationContext
loaded by the DispatcherServlet
when its init()
method is called. Since the init()
method of a Servlet
is called after the contextInitialized()
method of a ServletContextListener
is called, the DispatcherServlet
has access to the root context set as an attribute in the ContextLoaderListener
and can therefore use the beans declared there.
[...] creates the beans defined there, overriding the definitions of any
beans defined with the same name in the global scope.
A bean definition is, for example,
<bean id="someBean" class="com.company.SomeBean">
<property name="someProp" value="some value" />
</bean>
Spring creates a BeanDefinition
object for this and all other <bean>
declarations (or @Bean
annotation methods). When the ApplicationContext
is refreshed, Spring generates actual instances from these bean definitions.
What the above quote from the documentation is saying is that if you have a <bean>
declaration with the same name
or id
in both the root context and the servlet context, the servlet context one will overwrite the root context one.