Eclipse中有如下代码
InfTestAdd.java
package sunview.com;
public interface InfTestAdd {
public int Add(int a);}*******************************************
InfTestJian.java
package sunview.com;public interface InfTestJian {
public int Jian(int a,int b);}
************************************************
Test.java
package sunview.com;import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;@Stateless
@Remote({InfTestAdd.class})
@Local({InfTestJian.class})
public class Test implements InfTestAdd,InfTestJian{private int result=0;
public Test(){}
public int Add(int a) {
// TODO Auo-generated method stub
result+=a;
return result;
}public int Jian(int a, int b) {
// TODO Auto-generated method stub
result=a-b;
return result;
}}
****************************************
以上是EJB包,在JBOSS中能正常发布,没有异常抛出!
StatelessTest.java
package sunview.com.testejb;import java.util.Properties;import javax.naming.InitialContext;
import javax.naming.NamingException;import sunview.com.Test;public class StatelessTest {public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.provider.url",
"127.0.0.1:1099");
props.setProperty("java.naming.factory.url.pkgs",
"org.jboss.naming");try {
InitialContext ic=new InitialContext(props);
//Test testR=(Test) ic.lookup("sunview.com.Test/remote");
Test testR=(Test) ic.lookup("sunview.com.Test/local");
//System.out.println("0+100="+testR.Add(100));
System.out.println("100-50="+testR.Jian(100,50));} catch (NamingException e) {
e.printStackTrace();

}}
********************************
用StatelessTest来测试时抛出如下异常javax.naming.NameNotFoundException: sunview.com.Test 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.GeneratedMethodAccessor82.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.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:589)
at javax.naming.InitialContext.lookup(Unknown Source)
at sunview.com.testejb.StatelessTest.main(StatelessTest.java:27)
***********************************不管用remote,还是local,都是这样的!
我查了好久不明白那里有问题,
求人指点!!!

解决方案 »

  1.   

    我初学 ejb 哦,
    Test testR=(Test) ic.lookup("sunview.com.Test/local");  
    这段代码应该是查找 你 ejb 接口的名字?
    比如 InfTestAdd  add =(InfTestAdd)ic.lookup(InfTestAdd.class.getName)
      

  2.   

    Test testR=(Test) ic.lookup("这个里的名字是你ejb-jar.xml文件中的name");   
    好像你的ejb 建的有误吧!
      

  3.   

    Test testR=(Test) ic.lookup("这个里的名字是你ejb-jar.xml文件中的name");   
    好像你的ejb 建的有误吧!