【发布时间】:2016-03-26 12:38:20
【问题描述】:
环境:
春季 4
休眠 4
MySQL
Spring MVC REST
问题:
我正在为 CRUD 操作编写一个简单的基于 REST 的应用程序。
架构/组件如下:
我有以下设计问题:
1. 在 Spring Application 中,最好的做法是拥有两个独立的上下文 -
i) applicationContext :通过 ContextLoaderListener 初始化(用于服务 abd daoLayerClasses)
ii) webApplicationContext:通过 Dispather servlet 初始化(用于控制器/视图解析器)
2. 但是,我没有看到任何使用上述两个上下文的示例基于 Spring REST 的应用程序。仅使用 Dispatcher servlet 方法。
3. 那么,如上述架构所示,为基于 REST 的应用程序创建两个单独的上下文会不会是矫枉过正和不必要的?
或者最好在 WebApplicationContext (@RestController) 和 ApplicationContext 中创建两个上下文分隔 SPRING REST 层
(@Services,@Repository)
【问题讨论】:
-
这也可能有助于解释为什么使用 2 个上下文:stackoverflow.com/questions/18682486/…
标签: spring hibernate rest spring-mvc