Spring/Hibernate 世界中的会话外观 - 它仍然相关吗?

发布于 2024-11-29 15:06:31 字数 98 浏览 0 评论 0原文

我们如何在 Spring 应用程序中实现 Session Facade 设计模式?会话外观的角色是否仅由服务 bean 类来提供,该服务 bean 类将为事务进行注释并具有会话范围?

How would we implement a Session Facade design pattern in the Spring application? Would the role of the Session facade be simply served by the service bean class that would be annotated for the transactions and will have a session scope?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈情不如逗狗 2024-12-06 15:06:31

Spring 服务(具有单例范围)就像本地无状态会话 bean,它是 Session Facade 模式的实现,仅适用于非分布式应用程序。 Spring 确实表明,在大多数情况下,服务不需要分布式,并且 Session Facade 的分布式方面并不像 J2EE 所描述的那样普遍。

(当你说“会话范围”时,听起来你混淆了事务中的会话和 HttpSession 中的会话,因为 Spring 使用术语会话范围来指代 HttpSession。(至少它让我对它的意图感到困惑。)我的阅读会话外观描述让我思考它与 HttpSession 没有任何关系。)

无论如何,我想说封装复杂性的基本目标仍然有效。在某些情况下,提供分布式访问的目标仍然非常有效,只是它不是 J2EE 试图实现的默认情况。 Seam 证明有状态会话 bean 仍然具有相关性。

A Spring service (with singleton scope) is like a local stateless session bean, it is an implementation of the Session Facade pattern, only for applications that are not distributed. Spring does make the case that in most cases services don't need to be distributed and that the distributed aspects of Session facade are not as all-pervasive as J2EE made them out to be.

(When you say "session scope" it sounds like you're confusing session as in transactional with session as in HttpSession, because Spring uses the term session scope to refer to HttpSessions. (At least it's confusing me about what's intended.) My reading of the Session facade description leads me to think it doesn't have anything to do with an HttpSession.)

Anyway, I'd say the basic goal of encapsulating complexity is still valid. In some cases the goal of giving distributed access is still very valid, it's just not the default case like J2EE tried to make it out to be. And Seam makes a case for stateful session beans still being relevant.

回眸一笑 2024-12-06 15:06:31

会话应该与 Web 层相关联,而不是与服务相关联。

服务确实拥有事务,因此它们应该具有该注释。

Session should be associated with the web tier, not services.

Services do indeed own transactions, so they should have that annotation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文