我正在创建一个EJB应用程序,我在下面使用它来获取上下文
Context context = new InitialContext();
StudentEJBRemote remoteHandle;
remoteHandle = (StudentEJBRemote) context.lookup("java:global/stadikon_hw2/swe645a1/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote");
当我尝试这样做时,我得到以下错误。
javax.naming.NameNotFoundException: stadikon_hw2/swe645a1/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote -- service jboss.naming.context.java.global.stadikon_hw2.swe645a1."StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote"
org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
javax.naming.InitialContext.lookup(InitialContext.java:411)
masonsurvey.SurveyAction.execute(SurveyAction.java:37)
我已将客户端应用程序和EJB部署在JBoss的.ear文件中。客户端应用程序.war文件包含远程接口类的jar。
从日志中我可以看到绑定发生了。
17:01:18,821 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named StudentEJB in deployment unit subdeployment "stadikon_session_hw2.jar" of deployment "stadikon_hw2.ear" are as follows:
java:global/stadikon_hw2/stadikon_session_hw2/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:app/stadikon_session_hw2/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:module/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:jboss/exported/stadikon_hw2/stadikon_session_hw2/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:global/stadikon_hw2/stadikon_session_hw2/StudentEJB
java:app/stadikon_session_hw2/StudentEJB
java:module/StudentEJB
答案 0 :(得分:0)
我通过在源代码中添加属性来解决这个问题。
// Configure JNDI properties.
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:1099");
jndiProps.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming.org.jnp.interfaces");
Context context = new InitialContext();