6

Why do we need applicationContext.xml in Spring?

In what situation would we use it? Do you have an example?

What is the difference between applicationContext.xml and spring-servlet.xml?

How can we compare applicationContext.xml in Spring with Struts.xml in Struts for easy understanding?

2
  • 1
    What research on this have you done yourself? What don't you understand, having done your research, and why don't you understand it? Commented Aug 7, 2013 at 11:40
  • viralpatel.net/blogs/… looks good as first overwiev Commented Aug 7, 2013 at 11:40

3 Answers 3

8

Why do we need applicationContext.xml in Spring?

In the early days of Spring framework, Application context i.e the various weave and settings necessary to bootstrap, coordinate and control all objects, where done using XML file. Although one can break various settings and dependency injection into several context files, this process has been made easier In Spring 2.5 and later by annotation-driven settings.

What is the difference between applicationContext.xml and spring-servlet.xml?

In a MVC based project, again if you're not using annotation-driven weaving mechanism for your project, all your endpoint servlets can be setup in the spring-servlet.xml. Note that the name of the file is always self chosen.

How can we compare applicationContext.xml in Spring with Struts.xml in Struts for easy understanding?

They are both similar in terms of what they're trying to achieve. i.e a central location for the application bootstrap settings. Similarly, all settings can be tiered into different files to make it modular.

Sign up to request clarification or add additional context in comments.

Comments

4

applicationContext comes from Spring Framework: it manages the business/DAO beans.

spring-servlet comes from Spring MVC: it manages the web beans.

Comments

3

A Web application can have many servlets running at the same time, therefore:

spring-servlet.xml will hold beans only visible to a particular servlet.

You could have many different servlets running

spring-servlet2.xml
spring-servlet3.xml
messaging-servlet.xml 

etc.

applicationContext.xml will hold application wide beans. Therefore all the servlets running will have access to the beans defined in applicationContext.xml. However, this is a one way dependency, your servlets can access you applicationContext.xml beans but your applicationContext cannot access any of your servlet beans.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.