我已经在war文件(不是ear文件)中部署了ejb。 我之前已成功使用了部署在ear文件中的ejb,但现在我收到javax.naming.NameNotFoundException,因为我的EJB托管在war文件中。如果我的 Web 应用程序名为 SpeechServices,并且该 bean 位于 com.xyz.ejb 包下且其名称为 Service,那么我应该使用什么 JNDI 查找字符串? 我现在正在使用以下内容。
ServiceRemote remote = (ServiceRemote) ct.lookup("SpeechServices/Service/remote-com.xyz.ejb.ServiceRemote");
请帮我纠正上面语句中的错误。
我的完整代码如下,如果 ejbs 在耳朵里,它可以连接到它们,
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 以确保您使用的是正确的 key 。为此:
- 在 JMX-Console 中访问 JBoss:service=JNDIView
- 调用list()方法
- 验证您的 EJB 是否正确绑定(bind)并确认您使用的 key 正确
关于java - 部署在 JBOSS 上的 EJB 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6817929/