search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

0 votes
33 views
Are applicationContext.xml and spring-servlet.xml related anyhow in spring framework? Will the properties files declared in applicationContext.xml be available to DispatcherServlet? On a related note, why do I need a *-servlet.xml at all ? Why is applicationContext.xml alone insufficient?
asked Guru 27.1k points 31 50 97

1 Answer

0 votes
 
Spring lets you define multiple contexts in a parent-child hierarchy.
 
The applicationContext.xml defines the beans for the "root webapp context", i.e. the context associated with the webapp.
 
The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet's app context. There can be many of these in a webapp, one per Spring servlet (e.g. spring1-servlet.xml for servlet spring1, spring2-servlet.xml for servlet spring2).
 
Beans in spring-servlet.xml can reference beans in applicationContext.xml, but not vice versa.
 
All Spring MVC controllers must go in the spring-servlet.xml context.
 
In most simple cases, the applicationContext.xml context is unnecessary. It is generally used to contain beans that are shared between all servlets in a webapp. If you only have one servlet, then there's not really much point, unless you have a specific use for it.
 
 
answered Guru 24.6k points 29 52 81

Related questions

0 votes
2 answers 53 views
53 views
asked john Guru 27.1k points 31 50 97
0 votes
1 answer 61 views
61 views
asked smith Geek 15.3k points 16 41 63
0 votes
1 answer 60 views
0 votes
1 answer 24 views
0 votes
1 answer 21 views
21 views
asked sara Guru 24.6k points 29 52 81
...