简单的ejb例子中的jndi问题,谢谢你的指点
环境:
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>