【问题标题】:EJB3 Client LookupEJB3 客户端查找
【发布时间】:2012-01-10 15:25:28
【问题描述】:

我试图从独立的 Java 客户端调用 EJB,得到以下错误。

查找代码

String localJNDIName = "ejbremote:gcmsnew/gcmsutilbeans.jar/CustomerSurveyManageQstBean#com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote";
InitialContext ic = new InitialContext();
GCMSBaseRemote bean = (GCMSBaseRemote)ic.lookup(localJNDIName);

例外

javax.naming.ConfigurationException: NamingManager.getURLContext 找不到该方案的工厂:ejbremote at com.ibm.ws.naming.jndicos.CNContextImpl.checkForUrlContext(CNContextImpl.java:471) 在 com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:160) 在 com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179) 在 javax.naming.InitialContext.lookup(未知来源)在 com.test.EJBClientTest.main(EJBClientTest.java:18)

环境

RAD 7.5,EJB3。 Websphere 应用服务器 7.0。

【问题讨论】:

    标签: websphere ejb-3.0 jndi


    【解决方案1】:

    WebSphere Application Server 中不存在 ejbremote 方案(即使“ejblocal”确实存在)。尝试使用 ejb/ 前缀代替 ejbremote:

    有关详细信息,请参阅信息中心中的 EJB application bindings overview 主题。

    【讨论】:

    • 它就像魔术一样工作。您能否提供一些参考读物的提示以了解更多信息?
    • 我添加了一个信息中心链接,但如果您有其他问题,请告诉我。
    • @BrettKail 链接似乎已损坏。
    • IBM 似乎断开了链接。我对产品不再熟悉,无法找到替代品。对不起。
    【解决方案2】:

    您需要有存根文件来调用 EJB,所以首先生成存根文件。在 websphere 中,appserver bin 文件夹 createEJBStubs 中有可用的实用程序。

    【讨论】:

      【解决方案3】:

      由于这是一个独立的(“瘦”)客户端,您可能应该尝试这样的操作:

         Properties properties = new Properties();
         properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
         properties.setProperty(Context.PROVIDER_URL,"corbaloc:iiop:localhost:2809"); //localhost=the host where your EJB is located, 2809=BOOTSTRAP_ADDRESS port
         Context initCtx = new InitialContext(properties);
         Object homeObject = initCtx.lookup("com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote"); //by default the JNDI name of your Remote Interface is its full class name
         // Narrow to a real object
         csmo = (CustomerSurveyManageQstRemote) javax.rmi.PortableRemoteObject.narrow(homeObject, com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote.class);
      

      为了进行上述调用,您的类路径中还应该有适当的 Websphere Jars。

      【讨论】:

      • 我使用了其他名称,例如 java:global、ejblocal,这些名称不起作用并给出了一些奇怪的错误。这对我有用 .initCtx.lookup("com.smbcgroup.gcms.utility.bl.survey.CustomerSurveyManageQstRemote"); //默认情况下,远程接口的 JNDI 名称
      【解决方案4】:

      用于远程查找

      import java.io.IOException;
      import java.util.Hashtable;  
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class ServiceLocator {
          static String url = "corbaloc:iiop:localhost:2809";
          static String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";  
          static String jndi = "ejb/enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.remote.impl.interface";
      
      
          private static ServiceLocator serviceLocator = null;  
      
          InitialContext context = null;
      
          private ServiceLocator() throws NamingException, IOException { 
      
              Hashtable<String,String> env = new Hashtable<String,String> (); 
              env.put("java.naming.provider.url",  url ); 
              env.put("java.naming.factory.initial",  initial );
              context = new InitialContext(env);
          }
      
          public synchronized static ServiceLocator getInstance() throws NamingException, IOException {
      
              if (serviceLocator == null) {
                  serviceLocator = new ServiceLocator(); 
              }
      
              return serviceLocator;
          }  
      
          public Object getService(String jndiName) throws NamingException {
              return context.lookup(jndiName); 
          }
      
          public <T>T getRemoteObject(Class<T> remoteInterfaceClass) {
              try {
      
                  return (T)javax.rmi.PortableRemoteObject.narrow( context.lookup(jndi), remoteInterfaceClass);
      
              } catch (NamingException nexc) {
      
                  nexc.printStackTrace(); 
      
              }
              return null;
          }
      
      }
      

      用于本地查找

      import java.io.IOException;
      import java.util.Hashtable;  
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class ServiceLocator {
          static String url = "iiop://localhost";
          static String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";  
          static String jndi = "ejblocal:enterprise_app_name/ejb_web_project_name.jar/ejb_name#name.of.local.impl.interface";
      
      
      
          private static ServiceLocator serviceLocator = null;  
      
          InitialContext context = null;
      
          private ServiceLocator() throws NamingException, IOException { 
      
              Hashtable<String,String> env = new Hashtable<String,String> (); 
              env.put("java.naming.provider.url",  url ); 
              env.put("java.naming.factory.initial",  initial );
              context = new InitialContext(env);
          }
      
          public synchronized static ServiceLocator getInstance() throws NamingException, IOException {
      
              if (serviceLocator == null) {
                  serviceLocator = new ServiceLocator(); 
              }
      
              return serviceLocator;
          }  
      
          public Object getService(String jndiName) throws NamingException {
              return context.lookup(jndiName); 
          }
      
          public Object getService() throws NamingException {
              return context.lookup(jndi); 
          }
      
      }
      

      【讨论】:

        猜你喜欢
        • 2011-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-27
        • 2011-08-08
        相关资源
        最近更新 更多