我有以下CDI托管bean:
@Named
@SessionScoped
public class InfoPageController implements Serializable {
@Inject
private InfoPageMapper mapper;
}
在部署到GlassFish 4.1期间抛出以下异常:
Exception while loading the app : CDI deployment failure:WELD-001413: The bean Managed Bean [class de.triaconsulting.cashyourgame.fe.controller.InfoPageController] with qualifiers [@Default @Any @Named] declares a passivating scope but has a non-passivation-capable dependency Managed Bean [class de.triaconsulting.cashyourgame.fe.mapper.InfoPageMapper] with qualifiers [@Any @Default]
org.jboss.weld.exceptions.UnserializableDependencyException: WELD-001413: The bean Managed Bean [class de.triaconsulting.cashyourgame.fe.controller.InfoPageController] with qualifiers [@Default @Any @Named] declares a passivating scope but has a non-passivation-capable dependency Managed Bean [class de.triaconsulting.cashyourgame.fe.mapper.InfoPageMapper] with qualifiers [@Any @Default]
at org.jboss.weld.bootstrap.Validator.validateInjectionPointPassivationCapable(Validator.java:477)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:395)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:291)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:165)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:529)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:515)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:490)
at org.jboss.weld.bootstrap.WeldStartup.validateBeans(WeldStartup.java:419)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:90)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:225)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:131)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:328)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:496)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:539)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:535)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:534)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:565)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:557)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:356)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:556)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1464)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:109)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1846)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1722)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:189)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
这是如何引起的?如何解决?
答案 0 :(得分:14)
解决方案首先是解释:
您最简单的方法是将InfoPageMapper mapper
中的字段InfoPageController
标记为transient
:
@Named
@SessionScoped
public class InfoPageController implements Serializable {
@Inject
transient private InfoPageMapper mapper;
现在的解释是:
错误消息以可读语言表明:
bean InfoPageController,即SessionScoped,必须是 serializable,但它需要InfoPageMapper,但不是 可序列化的也不是瞬态的 - 不可能确定如何 序列化InfoPageController。
在CDI中,有一些范围(最常见的是SessionScope)要求bean可以序列化 - 主要是因为它们以某种方式连接到HTTP Session,它可以包含更多适合内存的对象,服务器可能需要不时将它们交换到磁盘。
看来你得到了这个,因为InfoPageController实现了Serializable。但根据Java序列化原则,这还不够。您需要确保Serializable类的所有成员字段都是以下之一: - 原始类型(int,boolean) - 可序列化的对象(所有序列化规则递归应用) - 该字段标有关键字transient(与私有关键字处于同一级别)
CDI的技巧是你可以将所有注入的字段标记为瞬态,因为当对象从磁盘反序列化到内存中时会再次注入它们。因此,您不会丢失瞬态对象,否则在反序列化时它将为null,因为它先前未存储到磁盘。
另一种解决方案是使注入的bean InfoPageMapper也可序列化。但随后问题可能会以注入InfoPageMapper的字段递归重复。 Transient关键字可以解决您遇到的问题,并且如果不需要,可以强制其他benas序列化。
答案 1 :(得分:1)
根据您的服务器错误消息,请检查de.triaconsulting.cashyourgame.fe.mapper.InfoPageMapper。 InfoPageMapper是否实现了Serializable?
在InfoPageController对象的Session Scope中注入InfoPageMapper对象。 会话范围对象及其成员需要序列化。所以InfoPageMapper对象必须能够序列化。
所以InfoPageMapper必须实现Serializable Interface。
如果您不想在InfoPageController中序列化InfoPageMapper对象,可以在此变量上设置transient关键字。