简体   繁体   English

重新部署后使用JSF 2防止ViewExpiredException

[英]Preventing ViewExpiredException with JSF 2 after redeploy

I have a problem where every time I redeploy my app, any existing sessions are broken and the requests result in a ViewExpiredException . 我有一个问题,每次我重新部署应用程序时,任何现有会话都中断,并且请求导致ViewExpiredException None of the advice in related questions or outside mailing list / forum posts seems to fix this issue. 相关问题或外部邮件列表/论坛帖子中的任何建议似乎都无法解决此问题。 I can redeploy the same WAR file completely unchanged and the behavior is the same. 我可以完全不变地重新部署相同的WAR文件,并且行为相同。

I'm using Apache MyFaces 2.2.0, Tomcat 7.0.56 and Primefaces 5.0. 我正在使用Apache MyFaces 2.2.0,Tomcat 7.0.56和Primefaces 5.0。

The message of the exception is No saved view state could be found for the view identifier: with whatever page would be requested. 异常的消息是No saved view state could be found for the view identifier:No saved view state could be found for the view identifier:将请求任何页面。 Primefaces' menubar is used for navigation, which seems to be implemented as a <form> with POST requests. Primefaces的menubar用于导航,似乎通过POST请求实现为<form> These messages occur both with those navigation options and other AJAX that uses POST. 这些消息与那些导航选项和其他使用POST的AJAX一起出现。

I have tried: 我努力了:

  1. Setting explicit org.apache.myfaces.SECRET and org.apache.myfaces.MAC_SECRET values, as seen in this document . 设置显式的org.apache.myfaces.SECRETorg.apache.myfaces.MAC_SECRET值,如本文档中所示
  2. Both client and server values for the javax.faces.STATE_SAVING_METHOD parameter. javax.faces.STATE_SAVING_METHOD参数的clientserver值。
  3. Ensuring all beans and their transitive fields are serializable. 确保所有bean及其传递字段都是可序列化的。 No serialization errors are reported in the logs. 日志中未报告任何序列化错误。
  4. Using a filter to add no-cache headers, eg as suggested in this answer . 使用过滤器添加无缓存标头,例如此答案中建议的。
  5. Session persistence is not disabled, that is my context.xml has <Manager pathname="" /> commented out. 会话持久性未禁用,即我的context.xml已将<Manager pathname="" />注释掉。

尝试:

<Manager className="org.apache.catalina.session.PersistentManager" saveOnRestart="true"/>

It seems that losing sessions is a "feature" of Tomcat since at least version 6 and continuing to version 7 when deploying via WAR file. 至少从第6版开始,丢失会话似乎是Tomcat的“功能”,并且在通过WAR文件进行部署时,它一直持续到第7版。 We have to copy an unpacked directory to avoid losing the sessions, because WAR changes cause an undeploy followed by a deploy , as opposed to a reload . 我们必须复制一个未压缩的目录,以避免丢失会话,因为WAR更改会导致undeploy deploy ,然后是deploy ,而不是reload

This bug report states: 错误报告指出:

There are ways to achieve an update to an application without dropping the sessions. 有一些方法可以在不删除会话的情况下实现对应用程序的更新。 The simplest is probably: 最简单的可能是:
- deploy as an exploded directory rather than a WAR -部署为分解目录而不是WAR
- update the files -更新文件
- touch web.xml to trigger a reload -触摸web.xml触发重新加载

The reason for the current behaviour is to prevent problems when WARs are updated in incompatible ways and anything other than a full undeploy followed by (essentially) a new deployment causes conflicts. 当前行为的原因是为了防止在WAR以不兼容的方式进行更新时发生问题,并且除了完全取消部署之后(基本上)是新部署导致冲突之外,都不会发生此问题。

This is still the case in the current Tomcat 7.0 documentation : 当前的Tomcat 7.0文档中仍然是这种情况:

Currently, application reloading (to pick up changes to the classes or web.xml file) is not supported when a web application is deployed directly from a WAR file. 当前,当直接从WAR文件部署Web应用程序时,不支持应用程序重新加载(以获取对类或web.xml文件的更改)。 It only works when the web application is deployed from an unpacked directory. 仅当从解压目录中部署Web应用程序时,它才起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM