Question

I was just thinking that when should I actually consider loading more than one application contexts in Spring? All so far I have been merging the context files with <include> such that only one application context loads up.

Do you have an idea about when to go for more than one application contexts in the same JVM?

Was it helpful?

Solution

When you need to use hierarchical contexts, for example - like Spring MVC does. Your "web" context is loaded separately from your "main" context, so stuff defined in "main" context (services / DAOs / etc) is available to "web" but not the other way around.

OTHER TIPS

I almost always create many Spring configuration files to separate out the different layers of my application, but I always load them all via a single application context. The way I see it, I am using Spring for "application assembly", wiring together the various components of my application. Loading two different contexts, in my way of thinking, does not make sense. There is only one app, and thus only one context needed. Perhaps my view is simplistic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top