简体   繁体   English

是否允许将 ejb 引用传递给 ejb 的已用 class?

[英]Is it allowed to pass-through an ejb references to a used class of an ejb?

I have an EJB3 stateless session bean that uses some other ejbs to do its work.我有一个 EJB3 无状态 session bean,它使用其他一些 ejb 来完成它的工作。 As I do not want to have all the logic in the ejb class itself, I created some classes which solve the problems.由于我不想在 ejb class 本身中拥有所有逻辑,因此我创建了一些解决问题的类。 These classes are called by the ejb.这些类由 ejb 调用。 To have the referenced ejbs in these classes I created a context object that holds the injected ejb references which is passed to the classes.为了在这些类中引用 ejb,我创建了一个上下文 object,其中包含传递给类的注入 ejb 引用。

My question: is this allowed to store ejb references in simple object fields or must I use some special ejb reference fields?我的问题:这是否允许在简单的 object 字段中存储 ejb 引用,或者我必须使用一些特殊的 ejb 引用字段? At first glance I can't see a reason why because everything is handled in one thread an transaction.乍一看,我看不出一个原因,因为一切都在一个线程中处理一个事务。

You can pass these EJB references and store them in these auxiliar classes without any risk.您可以毫无风险地传递这些 EJB 引用并将它们存储在这些辅助类中。

Nevertheless, EJB specification encourages you to implement all the logic of your system through EJBs.不过,EJB 规范鼓励您通过 EJB 实现系统的所有逻辑。 So, from EJB design philosofy, you should declare these "auxiliar" classes as EJBs also (they perform business logic in the end) and inject into them the needed EJBs references to reduce the coupling (specially if the former EJB doesn't even use the injected EJBs).因此,根据 EJB 设计理念,您应该将这些“辅助”类也声明为 EJB(它们最终执行业务逻辑)并向其中注入所需的 EJB 引用以减少耦合(特别是如果以前的 EJB 甚至不使用注入的 EJB)。

Again, if you don't do it and just pass the references manually, no technicall issue should arise.同样,如果您不这样做而只是手动传递引用,则不会出现技术问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM