无法从Java SE客户端访问EJB - 查找失败错误 [英] Cant access EJB from a Java SE client - Lookup Failed Error

查看:100
本文介绍了无法从Java SE客户端访问EJB - 查找失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Netbeans并正在尝试使用EJB。



我有两个项目(2个单独的应用程序)



1-一个名为EnterpriseApp的Java ME项目



2-一个名为Test



的标准Java SE项目这里是我所做的 - 在EnterpriseApp中,我生成了一个名为TestEJB的无状态EJB,包含本地和远程接口。对于远程项目选择,我选择了测试应用程序。
简而言之,bean代码看起来像这样

  @Stateless 
public class TestEjb实现TestEjbRemote,TestEjbLocal
{
@Override
public String Try()
{
returnHello World;
}
}

在Java SE客户端Project这里是我的主我尝试访问bean的类:

  public class Main 
{
public static void main(String [] args)
{
try
{
属性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。默认为localhost。只需要web服务器运行
#与一个不同的主机比appserver
org.omg.CORBA.ORBInitialHost = localhost
#optional。默认为3700.只有当目标orb端口不是3700时才需要。
org.omg.CORBA.ORBInitialPort = 3700

我在

  TestEjbRemote testEJB =(TestEjbRemote)ctx.lookup(stateless.TestEjbRemote ); 

javax.naming.NamingException:SerialContext中的'stateless.TestEjbRemote'的查找失败[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)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
在javax.naming.InitialContext.lookup(InitialContext.java:392)
在主。 main(Main.java:19)
引起的:javax.naming.NameNotFoundException:stateless.TestEjbRemote not found
at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248 )
在com.sun.enterprise.na com.un.enterprise.Ming.impl.TransientContext.lookup 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)
在java.lang.reflect.Method.invoke(Method.java:597)
在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)
在com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
在com.sun.corba.ee.impl.protocol。 CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:199)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
在com.sun.corba.ee。 com.un.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
在com.sun中。 corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324 )
在com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl $ WorkerThread.performWork(ThreadPoo lImpl.java:497)
在com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl $ WorkerThread.run(ThreadPoolImpl.java:540)

关于我如何解决这个问题的任何建议?

解决方案

概念上你做的一切都正确。
所以这应该是一些错名相关的问题。



好消息,你可以检查它:)



EJB一旦被应用服务器识别出来就被部署了。这意味着存根由AS创建并放入JNDI树中。
这意味着一旦服务器启动,您可以转到JNDI树查看器(通常是由aplpication服务器提供),并查看部署在哪里。
我相信,鉴于你已经正确设置了你的罐子,这应该是正常的。



希望这有帮助


I am using Netbeans and am experimenting with EJBs.

I have two projects (2 separate applications)

1- A Java ME Project called EnterpriseApp

2- A standard Java SE Project called Test

Now here is what I did - in EnterpriseApp I generated a stateless EJB called TestEJB with both local and remote interfaces. For the remote project selection I selected the Test App. In short the bean code looks like this

@Stateless
public class TestEjb implements TestEjbRemote, TestEjbLocal 
{
    @Override
    public String Try() 
    {
        return "Hello World";
    } 
}

And in the Java SE client Project here is my main class through which I am trying to access the 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();
        }
    }


}

This is the contents of JNDI.properties file

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

And I get this error at

 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)

Any suggestions on how I may resolve this issue ?

解决方案

conceptually you did everything right. So this should be some 'wrong-name' related issue.

Good news that you can check it :)

EJB once got recognized by the application server is deployed. This means that the stubs are created and put by the AS into the JNDI tree. This means that once the server is started, you can go to JNDI tree viewer (usually its supplied with the aplpication server) and see what's got deployed where. I believe, given you've set up your jars properly this should work.

Hope this helps

这篇关于无法从Java SE客户端访问EJB - 查找失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆