I found in Spring spec the following sentence:
"Spring MVC looks for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and creates the beans defined there, overriding the definitions of any beans defined with the same name in the global scope."
According that sentence I assume that every bean defined in ApplicationContext should be overwritten by beans with the same name in WebApplicationContext ?
Thus could anybody explain me why I got the error in the following code:
First I declared my ApplicationContext, WebApplicationContext and my own DispatcherServlet in web.xml:
Then I created bean "user" in AppContext and the same in WebAppContext:
At the end I implemented my version of DispatcherServlet where I retrieved bean "user":
When I run the code I got userName: TOM. So the bean "user" was taken from ApplicationContext - and this is my first WHY ? (it should be taken from WebAppContext so I should get value "JOHN")
After that I change the bean name in AppContext to userBis. And during running the code I got: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'user' is defined
And this is my second WHY? - it means that beans from WebAppContext weren't loaded ?