取消部署时,将 EJB 注入 SessionScoped ManagedBean 会生成异常

发布于 2024-12-23 11:57:01 字数 1995 浏览 3 评论 0原文

  1. 在 GlassFish 3.1 上使用 NetBeans 7 启动一个新的 Web 应用程序
  2. 在 index.xhtml 主体中添加一个 h:outputText 标记和 value="#{myBean.message}"
  3. 创建一个 < code>SessionScoped ManagedBean MyBean 具有名为 message 的字符串属性;创建 getter 和 setter;使其实现 Serialized
  4. 创建一个 Stateless SessionBean 并使用 @EJB 将其注入到 MyBean 中> 注解
  5. 从这一点开始,每当您更改 Java 代码并保存项目时,在取消部署期间您都会遇到大量错误(NPE、IOError、EJB 错误)。部署良好,应用程序运行良好。但我想避免取消部署期间出现异常。

这是正常的吗?或者我做错了什么?

这是我的代码:

Index.xhtml (正文部分)

    <h:body>
        <h:outputText value="#{myBean.message}"></h:outputText>
    </h:body>

MyBean.Java

@ManagedBean
@SessionScoped
public class MyBean implements Serializable {

    @EJB NewSessionBean nsb;

    public String getMessage() {
        return " " + nsb.toString();
    }

    public MyBean() {
    }
}

NewSessionBean.java

@Stateless
@LocalBean
public class NewSessionBean {
}

为了获取错误,只需加载网页即可,在消息字符串中添加一个空格,保存 java 文件(切换自动部署,否则手动重新部署)。

一些例外

EJB5014: Exception resolving object 
java.lang.NullPointerException at    
com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate$SerializableLocalObjectDelegate.createObject(EJBLocalObjectInvocationHandlerDelegate.java:158)

IOException while loading persisted sessions: java.io.IOException
java.io.IOException
at com.sun.ejb.base.io.EJBObjectInputStream.resolveObject(EJBObjectInputStream.java:114)

更新

如果我用 Named 替换 ManagedBean 注释,因此使用 CDI ,然后将 javax.faces.bean.SessionScoped 替换为 javax.enterprise.context.SessionScoped,我在取消部署时遇到了完全相同的问题,之后应用程序运行顺利。

抛出的异常和之前一模一样。

  1. Start a new web application using NetBeans 7 on GlassFish 3.1
  2. In index.xhtml body add an h:outputText tag with value="#{myBean.message}"
  3. Create a SessionScoped ManagedBean MyBean with a String property called message; create getter and setter; make it implement Serializable
  4. Create a Stateless SessionBean and inject it into MyBean using @EJB annotation
  5. From this point on, whenever you change the Java code and save the project, you will get plenty of errors (NPE, IOError, EJB errors) during undeployment. The deployment is fine, and the application runs well. But I would like to avoid the exceptions during undeployment.

Is this normal? Or am I doing something wrong?

Here my code:

Index.xhtml (body part)

    <h:body>
        <h:outputText value="#{myBean.message}"></h:outputText>
    </h:body>

MyBean.Java

@ManagedBean
@SessionScoped
public class MyBean implements Serializable {

    @EJB NewSessionBean nsb;

    public String getMessage() {
        return " " + nsb.toString();
    }

    public MyBean() {
    }
}

NewSessionBean.java

@Stateless
@LocalBean
public class NewSessionBean {
}

In order to get the errors, just load the web page, add a space in the message string, save the java file (having the auto deployment toggled, otherwise redeploy manually).

Some exceptions

EJB5014: Exception resolving object 
java.lang.NullPointerException at    
com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate$SerializableLocalObjectDelegate.createObject(EJBLocalObjectInvocationHandlerDelegate.java:158)

IOException while loading persisted sessions: java.io.IOException
java.io.IOException
at com.sun.ejb.base.io.EJBObjectInputStream.resolveObject(EJBObjectInputStream.java:114)

UPDATE

If I replace the ManagedBean annotations with Named, therefore using CDI, and consequently replace javax.faces.bean.SessionScoped with javax.enterprise.context.SessionScoped, I have exactly the same problem when undeploying, and afterwords the application runs smoothly.

The thrown exception is exactly the same as before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陈独秀 2024-12-30 11:57:01

您的服务器尝试序列化并保存 http 会话。您的会话 bean 应该是可序列化的,以使会话持久性可用。 Ir 看起来像这个参考:NewSessionBean nsb;不可序列化。您可以将其设置为暂时的,并且应该消除错误。但在会话恢复后,nsb 将为空。我不确定 EJB 中如何处理它,但必须以某种方式重新注入该引用。

Your server tries to serialize and save http session. Your session beans should me serializable to make session persistence available. Ir looks like this reference : NewSessionBean nsb; is not serializable. You can make it transient and you should get rid of error. But after sesson restore nsb will be null. I'm not sure how it's handled in EJB but this reference must be reinjected somehow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文