我一直试图让 Jetty 的会话持久性工作。它实际上是将会话写入磁盘,但它似乎没有将它们读回,因为当我的应用程序有机会读取会话时,我的会话数据已全部消失。
我们这样配置它:
HashSessionManager sessionManager = new HashSessionManager();
sessionManager.setStoreDirectory(new File("sessions"));
// If I don't put in this next line, it seems like it "never" saves sessions to disk.
// Or at least I don't have the patience to wait however long it must take to do so.
sessionManager.setSavePeriod(5);//seconds
// Supposedly if you don't turn this on it can cause problems for some of the things
// Wicket puts in the session because Jetty would otherwise initialise the objects in
// the session before Wicket itself initialises.
sessionManager.setLazyLoad(true);
// ...
servletHandler.setSessionHandler(new SessionHandler(sessionManager));
文档似乎没有提到任何明显的缺陷,除了我已经在上面的代码中通过启用延迟加载来克服的缺陷。但是该类中还有很多其他会话,并且几乎所有会话都没有在 Javadoc 中记录,因此除了挖掘其源代码以查找潜在错误之外,很难知道从这里去哪里......