以前都是用spring的,新项目要求用ejb3最近在做点小例子,同一份代码在glassfish上没问题,换成weblogic10就出错,先贴客户端代码,再贴异常信息:
客户端代码:public class Client { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Context jndiContext = getInitialContextForWeblogic();
Object ref = jndiContext.lookup("_appsdir_learnEjb3Project_dirlearnEjb3ProjectTravelAgent_TravelAgentRemote");
TravelAgentRemote dao = (TravelAgentRemote)PortableRemoteObject.narrow(ref, TravelAgentRemote.class);

// Cabin cabin_1 = new Cabin();
// cabin_1.setId(2);
// cabin_1.setName("Master Suite");
// cabin_1.setDeckLevel(1);
// cabin_1.setShipId(1);
// cabin_1.setBedCount(3);
//
// dao.createCabin(cabin_1);

Cabin cabin_2 = dao.findCabin(1);
System.out.println(cabin_2.getName());
}catch(javax.naming.NamingException ne){
ne.printStackTrace();
}
}

public static InitialContext getInitialContextForGlassFish() throws javax.naming.NamingException{
Properties props = new Properties();   
        props.setProperty("java.naming.factory.initial",   
                "com.sun.enterprise.naming.SerialInitContextFactory");   
        props.setProperty("java.naming.factory.url.pkgs",   
                "com.sun.enterprise.naming");   
        props.setProperty("java.naming.factory.state",   
                "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");   
  
        //EJB容器的ip   
        props.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");   
  
       //EJB容器端口,默认为:3700   
        props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");   
  
        InitialContext ic = new InitialContext(props);   
  
        return ic;    }

public static InitialContext getInitialContextForWeblogic() throws NamingException{
InitialContext ctx = null;  
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
        "weblogic.jndi.WLInitialContextFactory");
    p.put(Context.PROVIDER_URL, "t3://localhost:7001");
return new javax.naming.InitialContext(p); }}以下是异常信息:
  Exception in thread "main" java.lang.ClassCastException: Cannot narrow remote object weblogic.rmi.internal.BasicRemoteRef - hostID: '7077923596898578775S:127.0.0.1:[7001,7001,-1,-1,-1,-1,-1]:dev_domain:AdminServer', oid: '287', channel: 'null' to com.titan.travelagent.TravelAgentRemote
at weblogic.corba.server.naming.ReferenceHelperImpl.narrow(ReferenceHelperImpl.java:206)
at weblogic.rmi.extensions.PortableRemoteObject.narrow(PortableRemoteObject.java:88)
at weblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:32)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at com.titan.clients.Client.main(Client.java:24)在转化为远程接口的时候总是报java.lang.ClassCastException,同样的代码在GLASSFISH下没问题,当然JNDI名称是不同的。请各位熟悉WEBLOGIC的人说说这是咋回事??

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【dengcainiao】截止到2008-07-02 10:04:08的历史汇总数据(不包括此帖):
    发帖的总数量:8                        发帖的总分数:280                      
    结贴的总数量:3                        结贴的总分数:120                      
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:5                        未结的总分数:160                      
    结贴的百分比:37.50 %               结分的百分比:42.86 %                  
    无满意结贴率:0.00  %               无满意结分率:0.00  %                  
    楼主该结一些帖子了