Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.4k points)
  • 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?

1 Answer

0 votes
by (46k points)
Spring permits you to establish multiple contexts in a parent-child regime.

The applicationContext.xml describes the beans for the "root web app context", i.e. the connection associated with the web app.

The spring-servlet.xml (or whatever extra you call it) represents the beans for one servlet's app context. There can be several of these in a web app, 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, although not vice versa.

All Spring MVC controllers necessity go in the spring-servlet.xml context.

In the largest simple events, the applicationContext.xml context is irrelevant. It is usually applied to contain beans that are distributed among all servlets in a web app. If you only hold one servlet, then there's not enough point, except you have a particular use for it.

Browse Categories

...