java EJB - 'ejb/BookRequestBean' 的查找失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16481198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 23:05:42  来源:igfitidea点击:

EJB - Lookup failed for 'ejb/BookRequestBean'

javajakarta-eeejbejb-3.0glassfish-3

提问by Pradeep Simha

I am new to EJB, and was trying "Hello World" type of EJB Java program. Here is my EJB:

我是 EJB 新手,正在尝试“Hello World”类型的 EJB Java 程序。这是我的 EJB:

package dukesbookstore.ejb;
@Stateless(name="BookRequestBean", mappedName="ejb/BookRequestBean")
@Named
public class BookRequestBean {
    //Other codes here
}

and here is my client:

这是我的客户:

    Properties prop = new Properties();
    prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
    prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    try {
        InitialContext ctx = new InitialContext(prop);                              
        ctx.lookup("ejb/BookRequestBean");
        System.out.println("EJB Look-up successfull!!");
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

But whenever I try to run, I am getting below exception:

但是每当我尝试运行时,我都会遇到以下异常:

javax.naming.NamingException: Lookup failed for 'ejb/BookRequestBean' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java

javax.naming.NamingException:在 SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org. omg.CORBA.ORBInitialHost=本地主机,java

I have added appserv-rt.jar, gf-client.jar, javaee.jar, but still no luck. Can anyone help me, what I am missing here? I am usign Glassfish 3.1

我添加了appserv-rt.jar, gf-client.jar, javaee.jar,但仍然没有运气。谁能帮助我,我在这里缺少什么?我是用 Glassfish 3.1

采纳答案by Miljen Mikic

In addition to nice @RaviTrivedi answer, here are few thoughts:

除了不错的@RaviTrivedi 回答之外,这里还有一些想法:

  • @Namedannotation shouldn't be used this way
  • don't use both nameand mappedName, for Glassfish it is enough to use just mappedName
  • your EJB should implement remote interface
  • @Named不应该这样使用注释
  • 不要同时使用nameand mappedName,对于 Glassfish ,只使用就足够了mappedName
  • 你的 EJB 应该实现远程接口

回答by Ravi Trivedi

There can be several reasons to this:

这可能有几个原因:

1)Your EJBis not mapped to JNDIname. You need to check whether your EJBis deployed successfully and it is mapped to JNDIname. You can check Server GUI, Server Log on startupor use Universal Test Clientto see if EJBis mapped correctly. Note, UTCwill only show Remotely exposedEJBs.

1)EJB没有映射到JNDI名称。您需要检查您EJB的部署是否成功并映射到JNDI名称。您可以检查Server GUIServer Log on startup或用于Universal Test Client查看是否EJB正确映射。注意,UTC只会显示远程公开的EJB。

2)Your EJBis only exposed to Localapplication. In this case, Remote callor Cross application call(different EAR, WAR...) to your EJBwill fail. In this scenario, create Remote interfaceand expose it. Local interfaceexposes EJB to only local calls. Remote interfaceexposes EJB to remoteor cross application calls.

2)EJB只暴露给本地应用程序。在这种情况下,远程调用跨应用程序调用(不同的 EAR、WAR...)EJB将失败。在这种情况下,创建远程接口并公开它。本地接口只向本地调用公开 EJB。远程接口将 EJB 暴露给远程跨应用程序调用

3)Your RMI/IIOPportmay be incorrect. You can check Glassfish GUIor Server startup logto see what portRMI/IIOPis assigned to.

3)您的RMI/IIOP端口可能不正确。您可以检查Glassfish GUIServer startup log查看分配给哪个端口RMI/IIOP

Note:To diagnose the exact problem, please post full stack trace.

注意:要诊断确切的问题,请发布完整的堆栈跟踪。

回答by Igor Zelaya

Adding to @Ravi Trivedi and @Miljen Mikic, if you are using Glassfish, you should check how your EJB is registered in JNDI. In Glassfish for example type the following command:

添加到@Ravi Trivedi 和@Miljen Mikic,如果您使用的是Glassfish,您应该检查您的EJB 如何在JNDI 中注册。例如,在 Glassfish 中键入以下命令:

 asadmin list-jndi-entries