动态查找EJB [英] Looking up an EJB dynamically

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

问题描述

我正在Glassfish 3上开发一个应用程序。我有一个看起来像这样的EJB:

I'm developing an application on Glassfish 3. I have an EJB that looks like this:

@LocalBean
@Stateless
public class MyBean {
  public void doSomething() {}
}

我的客户端代码(在同一个应用程序中运行)如下所示:

My client code (running inside the same application) looks like this:

MyBean mb = (MyBean) InitialContext.doLookup(MyBean.class.getName());

根据一些消息来源,这应该是一个有效的查找方法,但它会抛出一个NameNotFoundException。我做错了什么?

According to a few sources, this should be a valid lookup method, but it throws a NameNotFoundException. What am I doing wrong?

推荐答案

根据什么来源?我个人会使用EJB 3.1中指定的可移植JNDI名称。请参阅:

According to what sources? I would personally use portable JNDI names specified in EJB 3.1. See:

  • Portable Global JNDI names by Mahesh Kannan
  • What is the syntax for portable global JNDI names in EJB 3.1? in GlassFish's EJB FAQ
  • Portable Global JNDI Names by Ken Saks
  • Application-specified Portable JNDI Names by Ken Saks

根据打包的不同,我会使用模块作用域或应用程序作用域的JNDI名称。

Depending on the packaging, I would use a module-scoped or an application-scoped JNDI name.

BTW,GlassFish在部署时记录可移植的JNDI名称。

BTW, GlassFish logs the portable JNDI names at deployment time.

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

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