Why DispatcherServlet creates another application context?

To answer your first question, the DispatcherServlet creates a context because that’s how it allows itself to be configured, and if you have multiple DispatcherServlets in one app, they’d each need to be configured separately. Therefore each one gets its own context, and each of those contexts is separate from the “root” context, where all of your real, “working” beans should live so they can be shared between the other contexts. There have been a number of questions over the last couple of weeks that were spawned by confusion over this very issue. You might gain a better understanding of how things work by checking out the answers:

Spring XML file configuration hierarchy help/explanation

Declaring Spring Bean in Parent Context vs Child Context

Spring-MVC: What are a “context” and “namespace”?

Leave a Comment