我在war文件中部署了一个ejb(不是ear文件)。 我之前已成功使用了部署在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));I have deployed an ejb in a war file(not an ear file). I have successfully consumed an ejb deployed in an ear file previously but now I am getting javax.naming.NameNotFoundException because my EJB is hosted in the war file. If my web app is called SpeechServices and the bean is under com.xyz.ejb package and its name is Service then what will be the JNDI lookup string i should be using? I am using the following right now.
ServiceRemote remote = (ServiceRemote) ct.lookup("SpeechServices/Service/remote-com.xyz.ejb.ServiceRemote");Please help me rectify the error in above statement.
My full code is following, which works to connect to ejbs if they are in an ear,
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以确保使用正确的密钥。 去做这个:
在JMX-Console中访问JBoss:service = JNDIView 调用list()方法 验证EJB是否正确绑定并确认您使用的密钥是否正确Check the JNDI to make sure that you are using the right key. To do this:
Access JBoss:service=JNDIView in JMX-Console invoke list() method Verify whether your EJB is bound properly and confirm that the key you are using is correct更多推荐
发布评论