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
EJB - Lookup failed for 'ejb/BookRequestBean'
提问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 回答之外,这里还有一些想法:
@Named
annotation shouldn't be used this way- don't use both
name
andmappedName
, for Glassfish it is enough to use justmappedName
- your EJB should implement remote interface
@Named
不应该这样使用注释- 不要同时使用
name
andmappedName
,对于 Glassfish ,只使用就足够了mappedName
- 你的 EJB 应该实现远程接口
回答by Ravi Trivedi
There can be several reasons to this:
这可能有几个原因:
1)Your EJB
is not mapped to JNDIname. You need to check whether your EJB
is deployed successfully and it is mapped to JNDIname. You can check Server GUI
, Server Log on startup
or use Universal Test Client
to see if EJB
is mapped correctly. Note, UTC
will only show Remotely exposedEJBs.
1)您EJB
没有映射到JNDI名称。您需要检查您EJB
的部署是否成功并映射到JNDI名称。您可以检查Server GUI
,Server Log on startup
或用于Universal Test Client
查看是否EJB
正确映射。注意,UTC
只会显示远程公开的EJB。
2)Your EJB
is only exposed to Localapplication. In this case, Remote callor Cross application call(different EAR, WAR...) to your EJB
will 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/IIOP
portmay be incorrect. You can check Glassfish GUI
or Server startup log
to see what portRMI/IIOP
is assigned to.
3)您的RMI/IIOP
端口可能不正确。您可以检查Glassfish GUI
或Server 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