我已经在war文件(而不是ear文件)中部署了ejb。我以前已经成功地使用了部署在ear文件中的ejb,但现在我获得了javax.naming.NameNotFoundException,因为我的EJB托管在war文件中。如果我的web应用程序名为SpeechServices,bean在com.xyz.ejb包下,它的名称是服务,那么我应该使用的JNDI查找字符串是什么?我现在正在使用以下内容。
ServiceRemote remote = (ServiceRemote) ct.lookup("SpeechServices/Service/remote-com.xyz.ejb.ServiceRemote");
请帮我纠正上面声明中的错误。
我的完整代码如下,如果ejb在ear中,它可以连接到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));
发布于 2011-07-25 15:27:38
检查JNDI以确保您使用的密钥是正确的。为此,请执行以下操作:
发布于 2011-07-25 17:05:13
验证您是否已更新要使用的web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
我认为规范说,如果不在web.xml中处理EJB,就不会以JavaEE6的方式处理EJB。
https://stackoverflow.com/questions/6817929
复制相似问题