本文介绍了为什么要使用有状态会话bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

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

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

Actually I see that SLSB can be used as web-services and this is convenient. 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.

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

For example, we can't use SFSB from SLSB, because stateful objects can be used only from stateful context. We can't use DI in servlets, instead we should manually create SFSB instances using a JNDI lookup and then put it into the HttpSession object. It can't be a web-service.

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

The only benefit 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 imagine that it can be really useful, when we store our data in an XML file and use transaction management in SFSB to manage non-relational DB.

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

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

推荐答案

你的意思是购物车?这是我能想到的明显答案。

You mean like a shopping cart? That's the obvious answer that I can think of.

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

You can think of EJBs as one way to deploy distributed services, but be careful. The term "web services" makes most people think of "SOAP-based web services using HTTP protocol", and that's not what you have in a SFSB.

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

This paragraph is confusing, but I think you're saying you don't like EJBs much.

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

Right, they're complementary. You use SFSB for use cases that require - wait for it - state to be maintained between calls.

servlet来自哪里?

Where did servlets come from here?



I think you're totally off base here. Sessions beans are the ones that know about units of work and managing transactions. They probably have to work with entity beans to persist some of that state when the use case is done, so transactions aren't as uncommon as you seem to think.



What's your expectation? That someone will post working SFSB? I'm not going to do that, mostly because I'm not a big EJB fan. (I do everything you're alluding to and more with Spring.)

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

But rest assured that SFSB are sometimes useful. The shopping cart is the obvious example. You need a place to maintain items in the cart until the customer decides to purchase. SFSB is one way to accomplish that.

这篇关于为什么要使用有状态会话bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 23:21