我已经在war文件(不是ear文件)中部署了ejb。 我已经成功地使用了先前部署在ear文件中的ejb,但现在我得到了javax.naming.NameNotFoundException,因为我的EJB托管在war文件中。如果我的web应用程序被称为SpeechServices,并且该bean在com.xyz.ejb包下,并且它的名称是Service,那么应该使用的JNDI查找字符串是什么? 我现在正在使用以下内容。部署在JBOSS上的EJB的端点
ServiceRemote remote = (ServiceRemote) ct.lookup("SpeechServices/Service/remote-com.xyz.ejb.ServiceRemote");
请帮我纠正上述错误。
我完整的代码如下,其工作方式连接到EJB的,如果他们在耳,
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
env.put(Context.SECURITY_PRINCIPAL, "admin");
env.put(Context.SECURITY_CREDENTIALS, "admin");
env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.security.jndi.JndiLoginInitialContextFactory");
InitialContext ct = new InitialContext(env);
ServiceRemote remote = (ServiceRemote) ct.lookup("SpeechServices/Service/remote-com.xyz.ejb.ServiceRemote");
System.out.println(remote.parseNotes(null, null, null));
非常感谢,它被绑定为全局JNDI命名空间,所以连接字符串是“Service/remote-com.ecw.ejb.ServiceRemote”没有应用名称追加到?这是好还是坏? – Sap
我没有看到任何问题。顺便说一句,如果你不喜欢默认的名称,你可以提供你自己的JNDI名称。对于自定义名称,您需要使用LocalBinding/RemoteBinding注释或其等效XML。 – helios
如果解决方案适用于您,您可能想接受答案:-) – helios