Spring - When should I consider loading another context in same JVM?

送分小仙女□ 提交于 2019-12-11 00:24:28

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1428439/spring-when-should-i-consider-loading-another-context-in-same-jvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!