我正在使用Netbeans并正在尝试使用EJB。
我有两个项目(2个独立的申请)
1-一个名为EnterpriseApp的Java ME项目
2-名为Test
的标准Java SE项目现在就是我所做的 - 在EnterpriseApp中,我生成了一个名为TestEJB的无状态EJB,同时具有本地和远程接口。对于远程项目选择,我选择了测试应用程序。 简而言之,bean代码看起来像这样
@Stateless
public class TestEjb implements TestEjbRemote, TestEjbLocal
{
@Override
public String Try()
{
return "Hello World";
}
}
在Java SE客户端项目中,这里是我尝试访问bean的主要类:
public class Main
{
public static void main(String[] args)
{
try
{
Properties props = new Properties();
props.load(new FileInputStream("jndi.properties"));
InitialContext ctx = new InitialContext(props);
TestEjbRemote testEJB = (TestEjbRemote) ctx.lookup("stateless.TestEjbRemote");
System.out.println(testEJB.Try());
}
catch (NamingException nex)
{
nex.printStackTrace();
}
catch (FileNotFoundException fnfex)
{
fnfex.printStackTrace();
}
catch (IOException ioex)
{
ioex.printStackTrace();
}
}
}
这是JNDI.properties文件的内容
java.naming.factory.initial = com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs = com.sun.enterprise.naming
java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
#optional. Defaults to localhost. Only needed if web server is running
#on a different host than the appserver
org.omg.CORBA.ORBInitialHost = localhost
#optional. Defaults to 3700. Only needed if target orb port is not 3700.
org.omg.CORBA.ORBInitialPort = 3700
我在
处收到此错误 TestEjbRemote testEJB = (TestEjbRemote) ctx.lookup("stateless.TestEjbRemote");
javax.naming.NamingException: Lookup failed for 'stateless.TestEjbRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: stateless.TestEjbRemote not found]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at Main.main(Main.java:19)
Caused by: javax.naming.NameNotFoundException: stateless.TestEjbRemote not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:199)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1486)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)
有关如何解决此问题的任何建议?
答案 0 :(得分:1)
您可以查看它的好消息:)
EJB一旦被应用程序服务器识别就被部署了。这意味着存根由AS创建并放入JNDI树中。 这意味着一旦服务器启动,您就可以转到JNDI树查看器(通常是随aplpication服务器提供的),并查看在哪里部署了什么。 我相信,鉴于你已正确设置你的罐子,这应该有效。
希望这有帮助