abhi jitnag wrote:In dispatcher-servlet we can do whatever we do in ApplicationContext.xml .
So why ApplicationContext.xml is used ?
Because Dispatcher Servlet is for the Web Layer/Tier, and the ContextLoaderListener/applicationContext.xml is for the middle tier. And just like in code, it is best to have seperation of concerns.
In many cases the teams working on the web layer know nothing about the middle tier and what beans to define for it. And the middle tier team provides a jar file tot he web tier with a Spring configuration already.
Yes, you can put all configuration in one big monolithic xml file and put it in your xxx-servlet.xml file, but that is one huge expensive xml file to maintain.