在无状态ejb中使用静态方法是否有意义? [英] Does it make sense to have static methods in stateless ejbs?

查看:86
本文介绍了在无状态ejb中使用静态方法是否有意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Stateles ejbs是幂等的,并且不存储先前的用户交互。对我来说,这听起来像是一种静态方法。

Stateles ejbs are intended to be idempotent and have no memory of previous user interactions. That sounds like a static method to me.

因此,
而不是让

so instead of having

 public void save(Entity e) { em.persist(e); }

是否安全?

 public static void save(Entity e) { em.persist(e); }

在EJB内部?

推荐答案

不,因为静态方法不参与容器管理的事务,AOP,安全性等。顺便说一句,第二个示例将无法编译, em 是由应用程序服务器注入的,它不能是静态的(?)

No, because static methods do not participate in container-managed transactions, AOP, security, etc. BTW your second example won't compile, em is injected by the application server and it can't be static (?)

此外,也没有这样的要求,即无状态EJB应该是幂等的并且没有状态(尽管有名字)。更不用说一旦开始使用 static 方法,就根本不需要EJB ...

Also there is no such requirement that stateless EJBs should be idempotent and have no state (despite the name). Not to mention that once you start using static methods, you don't need EJBs at all...

这篇关于在无状态ejb中使用静态方法是否有意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆