以前都是用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的人说说这是咋回事??
客户端代码: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的人说说这是咋回事??
解决方案 »
- 跪求Struts2达人帮忙啊
- 软件工程试题求解答?求大家给个指导
- 怎么实现按记录条数来排序
- 在ssh整合中出现java.sql.SQLException: No suitable driver错误
- 本人很烦恼!现在还是一个软件开发的门外汉,怎么样才能提高啊
- 给各位送分了。。。。。
- EJB中用到JDom解析XML文件,请问在Weblogic8中如何部署
- xml和properties文件的区别
- XPATH出错,帮忙看看~~java.lang.NoClassDefFoundError: org/jaxen/JaxenException
- 一个简单的html问题
- 怎样用Struts实现模糊查询
- struts2配置问题tomcat启动报错
楼主【dengcainiao】截止到2008-07-02 10:04:08的历史汇总数据(不包括此帖):
发帖的总数量:8 发帖的总分数:280
结贴的总数量:3 结贴的总分数:120
无满意结贴数:0 无满意结贴分:0
未结的帖子数:5 未结的总分数:160
结贴的百分比:37.50 % 结分的百分比:42.86 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主该结一些帖子了