【问题标题】:Could not invoke method getObjectInstance on object of type com.ibm.ws.naming.urlns.genericURLContextFactory error on JNDI lookup无法在 com.ibm.ws.naming.urlns.genericURLContextFactory 类型的对象上调用方法 getObjectInstance JNDI 查找错误
【发布时间】:2014-05-30 23:09:34
【问题描述】:

你知道我为什么会收到这个异常吗?

String url = "corbaloc:iiop:localhost:2809";
String initial = "com.ibm.websphere.naming.WsnInitialContextFactory";
String jndi = "ejblocal:my/ejb/PeriodoBO";

Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put("java.naming.provider.url", url);
pdEnv.put("java.naming.factory.initial", initial);
Context initialContext = new InitialContext(pdEnv);

try{
    Object ejbHome = initialContext.lookup(jndi); // <-- here
    Object obj = PortableRemoteObject.narrow(ejbHome, PeriodoBO.class);
}catch(NamingException e){
    System.err.println(e.toString());
}

我确定 JNDI 没问题,我很难得到它 (What's the default JNDI name of an EJB in Websphere Application Server 7 (WAS)?)。

你能帮帮我吗?

这是我的运行配置:

更新,我刚刚得到堆栈跟踪,我正在分析它:

WSCL0910I: Initializing component: com.ibm.ws.websvcs.component.WASAxis2ClientImpl
WSCL0911I: Component initialized successfully.
WSCL0910I: Initializing component: com.ibm.ejs.jms.JMSClientRegistration
WSCL0911I: Component initialized successfully.
WSCL0901I: Component initialization completed successfully.
WSCL0035I: Initialization of the Java EE Application Client Environment has completed.
WSCL0014I: Invoking the Application Client class xxxxx.tests.AllTests
.[02/06/14 17:21:45:963 COT] 00000000  W UOW=1-46884688-4040963:dmflores source=com.ibm.websphere.naming.genericURLInitialContextFactory org=IBM prod=WebSphere component=Application Server thread=[P=704708:O=0:CT]
          NMSV0907E: Could not invoke method "getObjectInstance" on object of type "com.ibm.ws.naming.urlns.genericURLContextFactory".
E.
Time: 0,011
There was 1 error:
1) testCursosLlevados(xxxxx.CursosTest)javax.naming.ConfigurationException: Could not invoke method getObjectInstance on object of type com.ibm.ws.naming.urlns.genericURLContextFactory. [Root exception is java.lang.reflect.InvocationTargetException]
    at com.ibm.websphere.naming.genericURLInitialContextFactory.getAndInvokeMethod(genericURLInitialContextFactory.java:480)
    at com.ibm.websphere.naming.genericURLContextFactory.getObjectInstance(genericURLContextFactory.java:165)
    at javax.naming.spi.NamingManager.getURLContext(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at xxxxxxx.tests.CursosTest.testCursosLlevados(CursosTest.java:59)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at xxxxxx.tests.AllTests.main(AllTests.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at com.ibm.ws.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:797)
    at com.ibm.ws.client.applicationclient.launchClient.main(launchClient.java:502)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at com.ibm.wsspi.bootstrap.WSLauncher.launchMain(WSLauncher.java:213)
    at com.ibm.wsspi.bootstrap.WSLauncher.main(WSLauncher.java:93)
    at com.ibm.wsspi.bootstrap.WSLauncher.run(WSLauncher.java:74)
    at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at org.eclipse.core.launcher.Main.invokeFramework(Main.java:340)
    at org.eclipse.core.launcher.Main.basicRun(Main.java:282)
    at org.eclipse.core.launcher.Main.run(Main.java:981)
    at com.ibm.wsspi.bootstrap.WSPreLauncher.launchEclipse(WSPreLauncher.java:341)
    at com.ibm.wsspi.bootstrap.WSPreLauncher.main(WSPreLauncher.java:111)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at com.ibm.websphere.naming.genericURLInitialContextFactory.getAndInvokeMethod(genericURLInitialContextFactory.java:466)
    ... 49 more
Caused by: javax.naming.ConfigurationException: There is no name space
    at com.ibm.ws.naming.urlns.genericURLContextFactory.isNameSpaceAccessable(genericURLContextFactory.java:96)
    at com.ibm.ws.naming.urlbase.UrlContextFactory.getObjectInstance(UrlContextFactory.java:84)
    ... 54 more

【问题讨论】:

  • 您从什么类型的程序中调用?它来自独立的 Java 应用程序吗? JEE 应用程序客户端?一个EJB?一个网络模块?什么?
  • 它来自 JEE 应用程序客户端。我将我的 websphere 从 7.0.0.0 更新到 7.0.0.31,但问题仍然存在。

标签: java jakarta-ee websphere jndi websphere-7


【解决方案1】:

ejblocal:my/ejb/PeriodoBO 指向本地接口。 Java EE 应用程序客户端无法访问本地接口。您需要远程接口。

将具有正确接口的@Remote 添加到您的bean。然后在应用程序初始化期间,您将在 SystemOut.log 中找到接口在 JNDI 中绑定到的绑定名称。 然后在 initialContext.lookup(jndi);使用那个 JNDI 名称。

希望对你有帮助

【讨论】:

  • 感谢 Gas,至少我没有遇到同样的错误。现在我有一个关于从存根接口转换为对象的问题(在查找方法旁边的行中),我明天将发布这个问题。谢谢!
  • 感谢 Gas,现在一切正常,但你能解释一下为什么它是远程的吗?是不是假设它在本地接口的同一个JVM中运行,因为它在ejb所在的同一个EAR中(如第一张图片)?
  • @DanielFlores 你写道你有一个 JEE 应用程序客户端 - 虽然应用程序客户端是通过调用 Ear 运行的,但它运行在单独的 JVM 中 - 客户端容器 - 它远程连接到应用程序服务器 JVM 和正在运行的组件那里。本地接口只能在同一个 JVM 中使用,它们不会发布到外部可访问的全局 JNDI。因此,因为您在外部 JVM 中,所以您必须使用远程 JVM。
【解决方案2】:

由于此代码是从 Java EE 应用程序客户端中调用的,并且 Java EE 应用程序客户端是由 WAS 库启动的,因此您拥有的大部分代码都是不需要的,也可能是您出现问题的原因。试试这个:

String jndi = "ejblocal:my/ejb/PeriodoBO";
Context initialContext = new InitialContext();
Object ejbHome = initialContext.lookup(jndi);
Object obj = PortableRemoteObject.narrow(ejbHome, PeriodoBO.class);

编辑,添加@Gas 的解决方案(它真正解决了您的问题的根源)。

【讨论】:

  • 对。为此,请添加 Gas 的建议。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
  • 2015-11-03
  • 1970-01-01
  • 2020-08-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多