Per the Spring Documentation, application context is:
Central interface to provide configuration for an application. This is read-only while the application is running, but maybe reloaded if the implementation supports this.
In some applications, there are multiple application contexts. What's the purpose and benefit of having multiple application contexts? I want to understand the logic behind it. Why would one do it?
P.S: In spring doc use is written. I want to know the pros of having multiple application contexts and the rationale behind it.
The
root contextis the parent of everydispatcher servlet context/child context. Beans defined inroot contextare visible to eachdispatcher servlet context/child contextbut not vice-versa.Typically,
root contextis used to define all cross-cutting beans such as security, transactions, and other configurational beans, while thedispatcher contextorchild contextcontains those beans that are specifically related toMVC.We create multiple
dispatcher servletswhen we need multiple sets ofMVCconfiguration. For e.g. we may have aREST APIalongside a traditionalMVCapplication or an unsecured and a secure section of a website.