Java 使用context.lookup加载远程接口时出现问题

Java 使用context.lookup加载远程接口时出现问题,java,ejb-3.1,jboss7.x,Java,Ejb 3.1,Jboss7.x,我曾经使用jboss 4.2.3 GA,在那里一切正常(至少从客户端调用远程接口)。现在我尝试用JBoss7.0.1 FINAL部署它 我(在服务器项目上)有这样一个类: @Remote(ConfigurationHelperRemote.class) @Local(ConfigurationHelperLocal.class) @Stateless public class ConfigurationHelper implements ConfigurationHelperRemote, C

我曾经使用jboss 4.2.3 GA,在那里一切正常(至少从客户端调用远程接口)。现在我尝试用JBoss7.0.1 FINAL部署它

我(在服务器项目上)有这样一个类:

@Remote(ConfigurationHelperRemote.class)
@Local(ConfigurationHelperLocal.class)
@Stateless
public class ConfigurationHelper implements ConfigurationHelperRemote,  ConfigurationHelperLocal {
   ...
}
我有远程接口

@Remote
public interface ConfigurationHelperRemote {
  ...
}
现在我习惯于在上下文的帮助下从客户端调用远程接口,如下所示:

configurationHelper = (ConfigurationHelperRemote) ctx.lookup("ear-1.0.0/ConfigurationHelper/remote");
但这已经不起作用了。现在我得到了这个错误消息

javax.naming.NameNotFoundException: Name 'ear-1.0.0' not found in context ''
我的ear文件名为ear-1.0.0.ear,其中的客户端名为client-1.0.0.war,服务器名为server-1.0.0.jar

这是ear文件中application.xml的内容

<?xml version="1.0" encoding="UTF-8"?>
<application 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/application_6.xsd" version="6">
   <display-name>ear</display-name>
     <module>
      <web>
       <web-uri>client-1.0.0.war</web-uri>
       <context-root>/client</context-root>
     </web>
    </module>
   <module>
    <ejb>server-1.0.0.jar</ejb>
   </module>
</application>

耳朵
客户端-1.0.0.war
/客户
server-1.0.0.jar
我需要在哪里配置上下文名称?或者我做错了什么

非常感谢大家的问候, 豪克

注:我刚刚打印了所有JNDI上下文信息,只有来自数据库的数据源。我这样做:

      public static void showJndiContext( Context ctx, String name, String space )
   {
      if( null == name  ) name  = "";
      if( null == space ) space = "";
      try {
         NamingEnumeration<NameClassPair> en = ctx.list( name );
         while( en != null && en.hasMoreElements() ) {
            String delim = ( name.length() > 0 ) ? "/" : "";
            NameClassPair ncp = en.next();
            System.out.println( space + name + delim + ncp );
            if( space.length() < 40 )
               showJndiContext( ctx, ncp.getName(), "    " + space );
         }
      } catch( javax.naming.NamingException ex ) {

      }
   }
公共静态void showJndiContext(上下文ctx、字符串名称、字符串空间)
{
如果(null==name)name=“”;
if(null==空格)space=“”;
试一试{
NamingEn=ctx.list(名称);
while(en!=null&&en.hasMoreElements()){
字符串delim=(name.length()>0)?“/”:“”;
NameClassPair ncp=en.next();
System.out.println(空格+名称+delim+ncp);
if(space.length()<40)
showJndiContext(ctx,ncp.getName(),“”+空格);
}
}catch(javax.naming.NamingException ex){
}
}

对于可移植JNDI语法,查找名称如下:

  • java:global[/application name]/模块名/企业bean名[/interface name]
  • java:module/enterprisebeanname/[接口名称]
  • java:app[/module name]/enterprisebean name[/interface name]
  • 您可以在中查看更多详细信息

    因此,对于您的代码,请尝试

    configurationHelper = (ConfigurationHelperRemote) ctx.lookup("java:global/ear-1.0.0/server-1.0.0/ConfigurationHelper");
    
    我在远程bean代码中使用的这种格式