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?
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.
applicationContext
comes from Spring Framework: it manages the business/DAO beans.
spring-servlet
comes from Spring MVC: it manages the web beans.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With