问题描述
源码:packagexx.xx;importjava.util.Properties;importjavax.naming.Context;importjavax.naming.InitialContext;importjavax.rmi.PortableRemoteObject;importcom.dc.eai.ejb.Service;importcom.dc.eai.ejb.ServiceHome;publicclassCtaisCon{privatestaticServiceHomehome;privatestaticServicebean;privatestaticContextgetInitialContext(){Stringurl="t3://91.16.16.117:7001";Stringuser="system";Stringpassword="security";Propertiesproperties=null;try{properties=newProperties();properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");properties.put(Context.PROVIDER_URL,url);if(user!=null){properties.put(Context.SECURITY_PRINCIPAL,user);properties.put(Context.SECURITY_CREDENTIALS,password==null?"":password);}returnnewInitialContext(properties);}catch(Exceptione){e.printStackTrace();}returnnull;}publicstaticvoidinitialize(){try{Contextcontext=getInitialContext();Objectref=context.lookup("dc/ejb/eai/eaiprocessor");home=(ServiceHome)PortableRemoteObject.narrow(ref,ServiceHome.class);bean=home.create();System.out.println("bean:"+bean);//bean.doService("","'");}catch(Exceptione){e.printStackTrace();}}publicstaticvoidmain(String[]args){initialize();}}异常:java.lang.ClassCastException:Cannotnarrowremoteobjecttocom.dc.eai.ejb.ServiceHomeatweblogic.iiop.PortableRemoteObjectDelegateImpl.narrow(PortableRemoteObjectDelegateImpl.java:242)atjavax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)atxx.xx.CtaisCon.initialize(CtaisCon.java:50)atxx.xx.CtaisCon.main(CtaisCon.java:64)Cannotnarrowremoteobjecttocom.dc.eai.ejb.ServiceHomeCannotnarrowremoteobjecttocom.dc.eai.ejb.ServiceHome求解。。。。