java JBoss EJB Bean 未绑定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2440956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:08:58  来源:igfitidea点击:

JBoss EJB Bean not bound

javajbossjakarta-eeejb-3.0jndi

提问by Don Ch

I have the following error

我有以下错误

 Exception in thread "main" javax.naming.NameNotFoundException: CounterBean not bound

trying to access an EJB JAR CounterBean.jar deployed on JBoss5 from a client application outside the Application Server.

尝试从应用服务器外部的客户端应用程序访问部署在 JBoss5 上的 EJB JAR CounterBean.jar。

From the Jboss log, it looks like it does not have a global JNDI name? Is this ok? What have I done wrong?

从Jboss日志看,好像没有全局JNDI名称?这个可以吗?我做错了什么?

JBoss log:

JBoss日志:

13:50:39,669 INFO  [JBossASKernel] Created KernelDeployment for: Counter.jar
13:50:39,672 INFO  [JBossASKernel] installing bean:   jboss.j2ee:jar=Counter.jar,name=CounterBean,service=EJB3
13:50:39,672 INFO  [JBossASKernel]   with dependencies:
13:50:39,672 INFO  [JBossASKernel]   and demands:
13:50:39,673 INFO  [JBossASKernel]      partition:partitionName=DefaultPartition;  Required: Described
13:50:39,673 INFO  [JBossASKernel]      jboss.ejb:service=EJBTimerService; Required: Described
13:50:39,673 INFO  [JBossASKernel]   and supplies:
13:50:39,673 INFO  [JBossASKernel]      jndi:CounterBean
13:50:39,673 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=Counter.jar,name=CounterBean,service=EJB3) to KernelDeployment of: Counter.jar
13:50:39,712 INFO  [SessionSpecContainer] Starting  jboss.j2ee:jar=Counter.jar,name=CounterBean,service=EJB3
13:50:39,727 INFO  [EJBContainer] STARTED EJB: com.don.CounterBean ejbName: CounterBean
13:50:39,732 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

The client code is:

客户端代码是:

public static void main(String[] args) throws NamingException, InterruptedException {
    InitialContext ctx = new InitialContext();
    Counter s = (Counter)ctx.lookup("CounterBean/remote");
    for(int i = 0; i < 100; i++ ) {
        s.printCount(i);
        Thread.sleep(1000);
    }
}

Error message:

错误信息:

java -Djava.naming.provider.url=jnp://123.123.123.123:1099 -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory com.don.Client

Exception in thread "main" javax.naming.NameNotFoundException: CounterBean not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
    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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
    at sun.rmi.transport.Transport.run(Transport.java:159)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at com.don.Client.main(Client.java:10)

回答by Pascal Thivent

This is what I get when I deploy a simple Stateless Session Bean (SLSB) with a remote interface on JBoss 5.x:

这是我在 JBoss 5.x 上部署带有远程接口的简单无状态会话 Bean (SLSB) 时得到的结果:

01:52:07,313 INFO  [JBossASKernel] Created KernelDeployment for: sandbox-services-1.0-SNAPSHOT.jar
01:52:07,313 INFO  [JBossASKernel] installing bean: jboss.j2ee:jar=sandbox-services-1.0-SNAPSHOT.jar,name=EchoBean,service=EJB3
01:52:07,314 INFO  [JBossASKernel]   with dependencies:
01:52:07,314 INFO  [JBossASKernel]   and demands:
01:52:07,314 INFO  [JBossASKernel]  jboss.ejb:service=EJBTimerService
01:52:07,314 INFO  [JBossASKernel]   and supplies:
01:52:07,314 INFO  [JBossASKernel]  Class:com.stackoverflow.q2440956.samples.services.hello.Echo
01:52:07,314 INFO  [JBossASKernel]  jndi:EchoBean/remote-com.stackoverflow.q2440956.samples.services.hello.Echo
01:52:07,314 INFO  [JBossASKernel]  jndi:EchoBean/remote
01:52:07,314 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=sandbox-services-1.0-SNAPSHOT.jar,name=EchoBean,service=EJB3) to KernelDeployment of: sandbox-services-1.0-SNAPSHOT.jar
01:52:07,315 INFO  [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@a130d1{name=jboss.j2ee:jar=sandbox-services-1.0-SNAPSHOT.jar,name=EchoBean,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}
01:52:07,381 INFO  [SessionSpecContainer] Starting jboss.j2ee:jar=sandbox-services-1.0-SNAPSHOT.jar,name=EchoBean,service=EJB3
01:52:07,382 INFO  [EJBContainer] STARTED EJB: com.stackoverflow.q2440956.samples.services.hello.EchoBean ejbName: EchoBean
01:52:07,412 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

    EchoBean/remote - EJB3.x Default Remote Business Interface
    EchoBean/remote-com.stackoverflow.q2440956.samples.services.hello.Echo - EJB3.x Remote Business Interface

When I look at the trace you provided, I can't see anything related to the remote interface (that you'll need for a remote call) and consequently, no JNDI name for it. So the question is: does your SLSB define and implement a remote interface properly?

当我查看您提供的跟踪时,我看不到任何与远程接口(远程调用所需的)相关的内容,因此,没有 JNDI 名称。所以问题是:您的 SLSB 是否正确定义和实现了远程接口?

In my case, my bean is defined like this:

就我而言,我的 bean 定义如下:

@Stateless
public class EchoBean implements Echo {
    ...
}

And the remote interface looks like:

远程接口看起来像:

@Remote
public interface Echo {
    String echo(final String in);
}

Do you have something similar?

你有类似的东西吗?