简单的ejb例子中的jndi问题,谢谢你的指点

flyseahappy 2008-05-08 10:57:17
环境:
XP SP2+Jboss 4.2+eclipse
出错的地方
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
public class MyTest {

public static void main(String[] args) {
Properties p=new Properties();
p.setPropert("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
p.setProperty("java.naming.provider.url", "localhost:1099");
p.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
try {
Context ctx = new InitialContext(p);
Object ref = ctx.lookup("Helloworld");//这里出了问题
HomeHello home = (HomeHello) PortableRemoteObject.narrow(ref,HomeHello.class);
RemoteHello user = home.create();
System.out.println(user.HelloEcho("So easy!"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
报错显示如下:
javax.naming.NameNotFoundException: Helloworld 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:296)
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:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
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:667)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.mytest.MyTest.main(MyTest.java:16)

我的jboss.xml 内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
<jboss>
<enterprise-beans>
<session>
<ejb-name>Helloworld</ejb-name>
<jndi-name>Helloworld</jndi-name>
</session>
</enterprise-beans>
</jboss>

我的ejb-jar.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>Neosue Helloworld Sample Application</description>
<display-name>Helloworld EJB</display-name>
<enterprise-beans>
<session>
<ejb-name>Helloworld</ejb-name>
<!-- home interface -->
<home>helloWorld.HomeHello</home>
<!-- remote interface -->
<remote>helloWorld.RemoteHello</remote>
<!-- bean implementation -->
<ejb-class>helloWorld.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

...全文
101 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xcjself 2008-05-13
  • 打赏
  • 举报
回复
进入 http://localhost:8080/jmx-console/,然后进入 service=JNDIView,可查看 JNDI 内容。
jack803 2008-05-13
  • 打赏
  • 举报
回复
Object ref = ctx.lookup("Helloworld/remote");
jack803 2008-05-13
  • 打赏
  • 举报
回复
是你的EJB没有发布成功,或者你找的jndi的名字错误javax.naming.NameNotFoundException: Helloworld not bound .你到JBOSS下面去找找看你发布的EJB的名字,一般就是你的EJB类的名字.
Object ref = ctx.lookup("Helloworld/remote");
这样看看行不行

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧