当前位置: 代码迷 >> JBoss >> 运行Stateless,Remote EJB时候报javax.naming.NameNotFoundException: FirstEjbBean not bound解决办法
  详细解决方案

运行Stateless,Remote EJB时候报javax.naming.NameNotFoundException: FirstEjbBean not bound解决办法

热度:10231   发布时间:2013-02-26 00:00:00.0
运行Stateless,Remote EJB时候报javax.naming.NameNotFoundException: FirstEjbBean not bound
1.环境:
myeclipse6.0+jboss-4.2.2.GA
2.jboss可以正常启动和关闭
3.我已经把%JBOSS_HOME%\client\*Jar加到客户端类中。
遇到问题:

javax.naming.NameNotFoundException: FirstEjbBean not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.mxf.ejb.FirstEjbClient.main(FirstEjbClient.java:22)

4.我的代码如下:
--接口
package com.mxf.ejb;
public interface FirstEjb {
public String sayHello(String str);
}

--接口实现Bean
package com.mxf.ejb;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Remote
@Stateless
public class FirstEjbBean implements FirstEjb {
public String sayHello(String str) {
return "您好!"+str;
}
}

--客户端
package com.mxf.ejb;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class FirstEjbClient {
public static void main(String[] args) {
try {
InitialContext itx = new InitialContext();
FirstEjb firstEjb = (FirstEjb)itx.lookup("FirstEjbBean/remote"); ---执行到这里报错
String str=firstEjb.sayHello("remain");
System.out.println(str);
} catch (NamingException e) {
e.printStackTrace();
}
}
}



------解决方案--------------------------------------------------------
用main函数应该不可以吧,做成web应用,放到jboss里就好了。
------解决方案--------------------------------------------------------
@Remote 
@Stateless 
这里要明确指定。
@Remote(FirstEjb.class)
@Stateless(FirstEjb.class) 
  相关解决方案