gpt4 book ai didi

java - 为什么要使用有状态 session bean?

转载 作者:搜寻专家 更新时间:2023-10-30 21:10:26 26 4
gpt4 key购买 nike

我正在学习 EJB3,我只是好奇什么时候方便使用 SFSB?当 SFSB 真正轻松解决一些复杂问题时,我找不到任何好的例子。

实际上我看到 SLSB 可以用作网络服务,这很方便。但是我不知道什么时候使用SFSB。我只看到它的问题,因为我们应该学习一些关于它的东西,我们应该编写由注释组成的代码,而不是完全,我们应该使用烦人的查找......我们没有得到任何好的返回。

例如,我们不能从 SLSB 使用 SFSB,因为有状态对象只能从有状态上下文使用。我们不能在 servlet 中使用 DI,而应该使用 JNDI 查找手动创建 SFSB 实例,然后将其放入 HttpSession 对象中。它不能是网络服务。

我在 SFSB 中看到的唯一好处是事务管理。但我认为当我们真的需要一个事务而不需要数据库时,这种情况很少见。我可以想象,当我们将数据存储在 XML 文件中并使用 SFSB 中的事务管理来管理非关系数据库时,它会非常有用。

我几乎可以肯定我完全错了,所以给我一些 SFSB 用法的非常好的例子。

最佳答案

I'm learning ejb3 and I'm just curious when it's convinient to use SFSB? I can't find any nice example when SFSB realy solve easily some complex problem.

你是说像购物车?这是我能想到的显而易见的答案。

Actually I see that SLSB can be used as web-services and this is convenient.

您可以将 EJB 视为部署分布式服务的一种方式,但要小心。术语“Web 服务”使大多数人想到“使用 HTTP 协议(protocol)的基于 SOAP 的 Web 服务”,而这不是 SFSB 中的内容。

But I don't know when to use SFSB. I see only problems with it because we should learn something about it, we should write code which consists of annotations a bit less then completely, we should use annoying lookup.. And we don't get anything good in return.

这一段令人困惑,但我认为您是在说您不太喜欢 EJB。

For example, we can't use SFSB from SLSB because stateful objects can be used only from stateful context.

是的,它们是互补的。您将 SFSB 用于需要 - 等待 - 在调用之间保持状态的用例。

We can't use DI in servlets, instead of it we should manually create SFSB instance using lookup and then put it to HttpSession object. It can't be a web-service.

servlet 是从哪里来的?

The only profit I can see in SFSB is a transaction management. But I think it's rare case when we really need a transaction and we don't need DB. I can suppose that it can be realy useful when we store our data in xml-file and use transaction management in SFSB to simulate nonrelational DB.

我认为你在这里完全偏离了基地。 session bean 是了解工作单元和管理事务的 bean。它们可能必须与实体 bean 一起工作,以便在用例完成时保留某些状态,因此事务并不像您想象的那样不常见。

I'm almost sure that I'm totally wrong, so give me some realy nice examples of SFSB usage.

您的期望是什么?有人会发布工作 SFSB 吗?我不会那样做,主要是因为我不是 EJB 的忠实粉丝。 (我用 Spring 做了你提到的一切,还有更多。)

但请放心,SFSB 有时很有用。购物车就是一个明显的例子。在客户决定购买之前,您需要一个地方来维护购物车中的商品。 SFSB 是实现这一目标的一种方式。

关于java - 为什么要使用有状态 session bean?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1686764/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com