我把客户端程序改做下面这样,但还是不知道怎样才能调用两台不同机子的ejb1,ejb2,
p.setProperty("java.naming.provider.url", "t3://210.80.197.105:7001");只能写一个IP呀???要怎么改变?package demo1;import javax.naming.*;
import java.util.Properties;
import javax.rmi.*;
import javax.ejb.*;
    public class Enterprise1TestClient3 extends Object {
      public static void main(String[] args)
       {
          try
          {
                   Properties p=new Properties(
 p.setProperty("java.naming.factory.initial", "weblogic.jndi.TengahInitialContextFactory");
   p.setProperty("java.naming.provider.url", "t3://210.80.197.105:7001");
             InitialContext jndiContext = new InitialContext(p);
             System.out.println("Got context");             // Get a reference to the Interest Bean
             Object ref  = jndiContext.lookup("Enterprise1");
             System.out.println("Got reference");             // Get a reference from this to the Bean's Home interface
             Enterprise1Home home = (Enterprise1Home)
             PortableRemoteObject.narrow(ref, Enterprise1Home.class);             // Create an Hello object from the Home interface
             Enterprise1 hello = home.create();             // call the hello() method
             System.out.println(hello.helloworld("ddd"));
          }
          catch(Exception e)
          {
             System.out.println(e.toString());
          }
       }
    }

解决方案 »

  1.   

    不行呀,我这个主要是想在多线程中实现,
    只能在一个程序中调用两台机子的EJB的.
      

  2.   

    把IP作为参数传入,在调用时传人IP参数,用HASHMAP缓存InitialContext ,试一试!
      

  3.   

    不能一起初始化两个home接口吗?
      

  4.   

    peopleking(蓝色幻想)大哥,你说把IP作为参数传入,在调用时传人IP参数,用HASHMAP缓存InitialContext的方法能否给个例子,比如我下面是用一个IP时做的,
    要调用两个IP的EJB,要怎么改?
     Properties p=new Properties();
      p.setProperty("java.naming.factory.initial", "weblogic.jndi.TengahInitialContextFactory");
            
     p.setProperty("java.naming.provider.url", "t3://211.80.197.105:7001");
      

  5.   

    把两个部署在不同机器上的EJB绑定到同一个JNDI服务器上,然后Home接口该怎么查就怎么查,完全不需要了解EJB究竟运行在哪里
      

  6.   

    Polarislee(北极星) 大哥,能否说具体点,
    怎么把不同机器上的EJB绑定到同一个JNDI服务器?
    你说的JNDI服务器是指weblogic上的管理服务器吗?