gpt4 book ai didi

java - 期待 NamingException,得到 NoSuchObjectException

转载 作者:行者123 更新时间:2023-12-01 15:13:20 25 4
gpt4 key购买 nike

我在 Weblogic 11g 上运行 Java 6。

我正在开发一个使用 EJB 与数据库通信的 Web 服务项目。目前我正在处理错误,因此我尝试在调用 Web 服务之前取消部署 EJB。我的 EJBClientHelper 类如下所示:

package mypackage.elkom.utils;

import java.io.Serializable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import mypackage.elkom.ejb.beans.session.remote.ElkomRemote;

public class EJBClientHelper implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

private ElkomRemote elkomRemote;

private static final String ELKOM_JNDI = "ElkomBean#mypackage.ejb.beans.session.remote.ElkomRemote";

private Context ctx;

private void prepareEjb3Connection() throws PropsFileException, NamingException {
// Here's code for getting the ejbProviderURL from propsfile //
props.put("java.naming.factory.initial", weblogic.jndi.WLInitialContextFactory");
props.put("java.naming.provider.url",ejbProviderURL);
ctx = new InitialContext(props);

}

public void setElkomRemote(ElkomRemote elkomRemote) {
this.elkomRemote = elkomRemote;
}

public ElkomRemote getElkomRemote() throws NamingException, PropsFileException {
prepareEjb3Connection();
if(elkomRemote == null) {
elkomRemote = (ElkomRemote)ctx.lookup(ELKOM_JNDI);
}
return elkomRemote;
}

}

但是,当我使用 getElkomRemote() 时;我收到以下消息,其中包含 NamingException:

SEVERE: The object identified by: '678' could not be found.  Either it was has not been exported or it has been collected by the distributed garbage collector.; 
nested exception is: java.rmi.NoSuchObjectException: The object identified by: '678' could not be found.
Either it was has not been exported or it has been collected by the distributed garbage collector.
javax.ejb.EJBException: The object identified by: '678' could not be found. Either it was has not been exported or it has been collected by the distributed garbage collector.;
nested exception is: java.rmi.NoSuchObjectException: The object identified by: '678' could not be found.
Either it was has not been exported or it has been collected by the distributed garbage collector.
java.rmi.NoSuchObjectException: The object identified by: '678' could not be found. Either it was has not been exported or it has been collected by the distributed garbage collector.

有人知道为什么我收到此消息而不是 NamingException 吗?也许如何解决它?

最佳答案

共有三种异常类别:

  • 系统异常
  • JVM 异常
  • 应用程序异常

由于代码错误或资源配置错误(例如 JNDI 查找配置错误),可能会发生系统异常。如果企业 Bean 遇到系统错误,它通常会抛出 javax.ejb.EJBException。容器将 EJBException 包装在 RemoteException 中,最后将 RemoteException 传回客户端。这就是您的情况发生的情况,这就是您收到 RemoteException 的原因。

系统异常无法从客户端应用程序处理,应作为未经检查的异常抛出。

有关更详细的信息,您可以参阅以下文章:

希望这对您有帮助。

关于java - 期待 NamingException,得到 NoSuchObjectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12002108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com