首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

Ejb的远程调用有关问题

2012-03-30 
Ejb的远程调用问题我刚学EJB3,写了个helloworld就出现问题了。帮忙看一下吧。服务器用JBOSS《服务器端》packag

Ejb的远程调用问题
我刚学EJB3,写了个helloworld就出现问题了。帮忙看一下吧。服务器用JBOSS

《服务器端》
package com.xxx.xxx.ejb;

public interface FirstEjb {
public String SaySomething(String name);
}


package com.xxx.xxx.ejb;

import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote
public class FirstEjbBean implements FirstEjb {

public String SaySomething(String name) {
return "FirstEjb " + name;
}

}

《客户端》
package com.xxx.xxx.ejb;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class EjbClient {

/**
* @param args
*/
public static void main(String[] args) {

try {
InitialContext context = new InitialContext();
FirstEjb firstEjb = (FirstEjb)context.lookup("FirstEjbBean/remote");
System.out.println(firstEjb.SaySomething("zhangsan"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

【JNDI.properties】

# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost


============================出现的异常================================

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(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$1.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:625)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.per.liubo.ejb.EjbClient.main(EjbClient.java:15)
=============================================================================

另外,怎么能在Ejb导入到JBOSS时,控制台显示导入的EJBBEAn的名字。谢谢了



[解决办法]
FirstEjbBean加上下面的注释:
@Remote(FirstEjb.class)
@RemoteBinding(jndiBinding = "FirstEjbBean/remote")

然后重新部署到jboss目录,重新启动jboss;

你现在错误的原因:1、ejb未部署成功;2、没有找到FirstEjbBean的名字
------解决方案--------------------


把bean打成jar包放到jboss -> default目录下了吗

热点排行