你知道为什么我会得到这个例外吗?
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
答案 0 :(得分:2)
ejblocal:my / ejb / PeriodoBO指向本地界面。 Java EE应用程序客户端无法访问本地接口。您需要远程接口。
为您的bean添加具有正确接口的@Remote。然后在应用程序初始化期间,您将在SystemNut.log绑定名称中找到该接口在JNDI中绑定的名称。 然后在initialContext.lookup(jndi);使用那个JNDI名称。
希望有所帮助
答案 1 :(得分:1)
由于此代码是从Java EE Application Client中调用的,并且WAM库启动了Java EE Application Client,因此您所拥有的大部分代码都是不必要的,也可能是您遇到问题的原因。试试这个:
String jndi = "ejblocal:my/ejb/PeriodoBO";
Context initialContext = new InitialContext();
Object ejbHome = initialContext.lookup(jndi);
Object obj = PortableRemoteObject.narrow(ejbHome, PeriodoBO.class);
编辑,添加@ Gas的解决方案(这真正解决了问题的根源)。