当前位置: 技术问答>java相关
初学ejb,小问题,请赐教。。。
来源: 互联网 发布时间:2015-04-24
本文导语: 我用jBuilder5照书上写了一个最简单的ejb,添加了一个简单的返回一个整数的方法,编译,发布都没有问题,weblogic5.1属性文件里面也配了,如下: weblogic.ejb.deploy= f:/weblogic/myserver/ejbgroup.jar #注册调用ejb的servlet weblogic...
我用jBuilder5照书上写了一个最简单的ejb,添加了一个简单的返回一个整数的方法,编译,发布都没有问题,weblogic5.1属性文件里面也配了,如下:
weblogic.ejb.deploy=
f:/weblogic/myserver/ejbgroup.jar
#注册调用ejb的servlet
weblogic.httpd.register.servlettest=ejbtest.Servlettest
weblogic启动信息里面也显示:
星期四 三月 23 11:02:45 CST 2000: Enterprise JavaBeans initializing
星期四 三月 23 11:02:48 CST 2000: EJB home interface: 'ejbtest
.testEnterpriseHome' deployed bound to the JNDI name: 'testEnterprise'
但是用servlet调用时,却出现异常:
something wrong!
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at ejb3.ejb3Servlet.init(ejb3Servlet.java:27)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:390)
at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:349)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:338)
at weblogic.servlet.internal.ServletStubImpl.checkForReload(ServletStubImpl.java:269)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:168)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:99)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:742)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:686)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:247)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
我调用ejb代码部分如下:
private testEnterpriseHome testEnterpriseHomeObject = null;
private testEnterprise testEnterpriseObject = null;
/**Initialize global variables*/
public void init() throws ServletException {
try {
//get naming context
Context ctx = getInitialContext();
//look up jndi name
Object ref = ctx.lookup("testEnterprise");
//cast to Home interface
//我跟踪了一下,下面这个语句跳出异常
testEnterpriseHomeObject = (testEnterpriseHome) PortableRemoteObject.narrow(ref, testEnterpriseHome.class);
testEnterprise testEnterpriseObject=testEnterpriseHomeObject.create();
int t=testEnterpriseObject.getTellerNo();
System.out.println("the number is:"+t);
}
catch (Exception e)
{
System.out.println("something wrong!");
e.printStackTrace();
}
}
private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
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);
}
return new InitialContext(properties);
}
catch(Exception e) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}
。。。
请各位大侠不吝赐教,多谢!
weblogic.ejb.deploy=
f:/weblogic/myserver/ejbgroup.jar
#注册调用ejb的servlet
weblogic.httpd.register.servlettest=ejbtest.Servlettest
weblogic启动信息里面也显示:
星期四 三月 23 11:02:45 CST 2000: Enterprise JavaBeans initializing
星期四 三月 23 11:02:48 CST 2000: EJB home interface: 'ejbtest
.testEnterpriseHome' deployed bound to the JNDI name: 'testEnterprise'
但是用servlet调用时,却出现异常:
something wrong!
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:296)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at ejb3.ejb3Servlet.init(ejb3Servlet.java:27)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)
at weblogic.servlet.internal.ServletStubImpl.createServlet(ServletStubImpl.java:390)
at weblogic.servlet.internal.ServletStubImpl.createInstances(ServletStubImpl.java:349)
at weblogic.servlet.internal.ServletStubImpl.prepareServlet(ServletStubImpl.java:338)
at weblogic.servlet.internal.ServletStubImpl.checkForReload(ServletStubImpl.java:269)
at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.java:168)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:99)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:742)
at weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImpl.java:686)
at weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContextManager.java:247)
at weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:361)
at weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)
我调用ejb代码部分如下:
private testEnterpriseHome testEnterpriseHomeObject = null;
private testEnterprise testEnterpriseObject = null;
/**Initialize global variables*/
public void init() throws ServletException {
try {
//get naming context
Context ctx = getInitialContext();
//look up jndi name
Object ref = ctx.lookup("testEnterprise");
//cast to Home interface
//我跟踪了一下,下面这个语句跳出异常
testEnterpriseHomeObject = (testEnterpriseHome) PortableRemoteObject.narrow(ref, testEnterpriseHome.class);
testEnterprise testEnterpriseObject=testEnterpriseHomeObject.create();
int t=testEnterpriseObject.getTellerNo();
System.out.println("the number is:"+t);
}
catch (Exception e)
{
System.out.println("something wrong!");
e.printStackTrace();
}
}
private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
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);
}
return new InitialContext(properties);
}
catch(Exception e) {
log("Unable to connect to WebLogic server at " + url);
log("Please make sure that the server is running.");
throw e;
}
}
。。。
请各位大侠不吝赐教,多谢!
|
testEnterpriseHomeObject = (testEnterpriseHome) PortableRemoteObject.narrow(ref, testEnterpriseHome.class);
你的类型转换有问题!去看看narrow()方法返回的是什么类型知道了吗!?
你的类型转换有问题!去看看narrow()方法返回的是什么类型知道了吗!?
|
是不是你已经在weblogic 里发布了另一个叫testEnterprise的东西?比如旧版本啊什么?如果有,去了它试试?
要不就不要叫testEnterprise,换一个名
要不就不要叫testEnterprise,换一个名