WELD-000227:检测到 Bean 标识符索引不一致 - 分布式容器可能不适用于相同的应用程序

WELD-000227: Bean identifier index inconsistency detected - the distributed container probably doesn't work with identical applications

在 eclipse IDE 中重新启动服务器并重新加载页面后,我将 tomcat v7 与 Weld v2.2.9.Final 和 myFaces v2.2.7 一起使用,我收到此错误。我不知道为什么这个错误出现在我身上。它必须与http请求相关联。如果我打开关闭浏览器,它就会开始工作。

SEVERE: Exception sending request initialized lifecycle event to listener instance of class org.jboss.weld.environment.servlet.Listener
org.jboss.weld.exceptions.IllegalStateException: WELD-000227: Bean identifier index inconsistency detected - the distributed container probably doesn't work with identical applications
    at org.jboss.weld.context.http.HttpSessionContextImpl.checkBeanIdentifierIndexConsistency(HttpSessionContextImpl.java:88)
    at org.jboss.weld.context.http.HttpSessionContextImpl.associate(HttpSessionContextImpl.java:42)
    at org.jboss.weld.context.http.HttpSessionContextImpl.associate(HttpSessionContextImpl.java:19)
    at org.jboss.weld.servlet.HttpContextLifecycle.requestInitialized(HttpContextLifecycle.java:217)
    at org.jboss.weld.servlet.WeldInitialListener.requestInitialized(WeldInitialListener.java:160)
    at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.requestInitialized(ForwardingServletListener.java:42)
    at org.apache.catalina.core.StandardContext.fireRequestInitEvent(StandardContext.java:6189)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1074)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

这是 Weld 中的错误。 https://issues.jboss.org/browse/WELD-1887

您应该可以通过在 Tomcat 中禁用会话钝化来解决问题。

org.jboss.weld.exceptions.IllegalStateException: WELD-000227: Bean identifier index inconsistency detected - the distributed container probably doesn't work with identical applications

当可序列化 class 的 Weld/CDI 代理实例在反序列化后发生不兼容的更改时(例如 Tomcat 重启后),将抛出此异常。您很可能在开发过程中编辑了一个可序列化会话或查看范围内的托管 bean,但没有触及 serialVersionUID。或者,您有 added/updated/removed 个与 CDI 相关的库。如果您在 Eclipse 中使用 Tomcat,请右键单击 Eclipse 的 Servers 视图中的 Tomcat 服务器条目,然后选择 Clean Tomcat工作目录。这将消除序列化会话,从而也解决此异常。

每当您在可序列化 class 中进行不兼容的更改时,例如添加新的实例字段,则您需要重新生成 serialVersionUID 值(如果您是 IDE-生成值),或将其值增加 1(如果您使用的是默认值 1L)。

因此,这不一定是 Weld 中的错误,但在我看来,它应该只是丢弃了不兼容的代理实例,创建了一个新的代理实例并打印了一条警告消息,而不是完全阻止带有此异常的请求。

如果您真的忙于开发并且每次都面临这个异常,请考虑关闭服务器中的会话持久性。如何执行此操作取决于所使用的服务器。对于 Tomcat 7,请参阅“Disable Session Persistence" in the documentation of The Manager Component.

部分

具体的消息"the distributed container probably doesn't work with identical applications"顺便说一句,当你是运行集群环境中的Web应用程序时可能出现的情况共享(例如云),显然至少一台服务器具有不同版本的 Web 应用程序。这种情况在生产中会导致这个异常。

另请参阅:

  • Java - When do I have to change the serialVersionUID?
  • org.jboss.weld.exceptions.IllegalStateException: WELD-000227 after every change in code

自上次发布答案以来可能已经过去两年多了,但如果您忘记在实体中实现 Serializable 也可能会发生这种情况 class。

(Java 8, Glassfish 4)

@Entity
@Table(name="questions")
public class Question { 
  ......
}

错误org.jboss.weld.exceptions.IllegalStateException:WELD-000227:检测到 Bean 标识符索引不一致 - 分布式容器可能不适用于相同的应用程序

@Entity
@Table(name="questions")
public class Question implements Serializable { 
  ......
}

删除浏览器 cookie 并重新加载页面。