取消部署时,将 EJB 注入 SessionScoped ManagedBean 会生成异常
- 在 GlassFish 3.1 上使用 NetBeans 7 启动一个新的 Web 应用程序
- 在 index.xhtml 主体中添加一个
h:outputText
标记和value="#{myBean.message}"
- 创建一个 < code>SessionScoped
ManagedBean
MyBean
具有名为message
的字符串属性;创建 getter 和 setter;使其实现Serialized
- 创建一个
Stateless
SessionBean
并使用@EJB
将其注入到MyBean
中> 注解 - 从这一点开始,每当您更改 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
,我在取消部署时遇到了完全相同的问题,之后应用程序运行顺利。
抛出的异常和之前一模一样。
- Start a new web application using NetBeans 7 on GlassFish 3.1
- In index.xhtml body add an
h:outputText
tag withvalue="#{myBean.message}"
- Create a
SessionScoped
ManagedBean
MyBean
with a String property calledmessage
; create getter and setter; make it implementSerializable
- Create a
Stateless
SessionBean
and inject it intoMyBean
using@EJB
annotation - 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的服务器尝试序列化并保存 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.