@EJB注释与JNDI查找 [英] @EJB annotation vs JNDI lookup

查看:173
本文介绍了@EJB注释与JNDI查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何情况,使用JNDI比使用 @EJB 注释注入无状态会话bean更好?



我们正在使用JSF 1.2与Sun Application Server 9.0_01。



我们的团队正在辩论在托管Bean中使用SLSB时哪种方法更好。 p>

我已经阅读了以下问题,但是想知道是否存在首选查找的情况。




解决方案


有什么情况下最好的o使用JNDI比使用@EJB注释注入
无状态会话bean?


没有更好的情况 - 但有必要的情况:




  • 当编译时不知道要查找的名称(我认为这是坏设计,但这又是另一个问题)

  • 当不支持注释时,例如在常规非托管类和其他几种情况下(我们可以再次争论是否依赖于EJB在这些类中是好还是坏)。



如果要查找的名称是恒定的,注入是可能的,更喜欢 @EJB 注释:




  • 使测试更容易

  • 找出本地/全局JNDI名称的麻烦较少


Is there any situation where it's better to use JNDI than to inject a stateless session bean using the @EJB annotation?

We're using JSF 1.2 with Sun Application Server 9.0_01.

Our team is debating which approach is better when using SLSBs in a Managed Bean.

I've read the following questions, but was wondering if there was a situation where lookup is preferred.

解决方案

Is there any situation where it's better to use JNDI than to inject a stateless session bean using the @EJB annotation?

There's no situation where it's better--but situations where it's necessary:

  • when the name to lookup is not known at compile time (I would argue that it's bad design, but that's another issue)
  • when annotations are not supported, e.g. in regular non-managed helper classes and few other cases (We could again argue about whether it's good or bad to depends on EJB in these classes).

If the name to look up is constant and injection is possible, prefer @EJB annotations:

  • Make testing easier
  • Less trouble figuring out local / global JNDI names

这篇关于@EJB注释与JNDI查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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