【问题标题】:Upgrading to jetty 9.4 replacing the HashSessionManager升级到 jetty 9.4 替换 HashSessionManager
【发布时间】:2018-03-02 02:45:45
【问题描述】:

升级到码头 9.4 后,我注意到 org.eclipse.jetty.server.session.HashSessionManager 的 ClassNotFoundException。 我想我需要使用FileSessionDataStore,但我不明白应该如何在SessionHandler 上设置。

我目前的配置是:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    ...
    <Set name="sessionHandler">
        <New class="org.eclipse.jetty.server.session.SessionHandler">
            <Arg> 
                <New class="org.eclipse.jetty.server.session.HashSessionManager">
                    <Set name="storeDirectory">my/store/path</Set>
                </New>
            </Arg>
        </New>
    </Set>
</Configure>

我看不出我需要做什么,SessionHandler 不需要 SessionDataStore,但可以在其上设置 SessionCache,但看起来 SessionCache 的实现需要 @987654329 @ 在构造函数中,我看不到如何在 XML 中做到这一点。

【问题讨论】:

    标签: jetty jetty-9


    【解决方案1】:

    在 jetty-9.4 会话架构中,SessionHandler 采用 SessionCache,它可以选择采用 SessionDataStore

    有关程序示例,请参阅OneServletContextWithSession

    该示例使用NullSessionDataStore,但原理与FileSessionDataStore 相同,后者是旧HashSessionManager 将会话存储到磁盘的功能的替代品。

    码头文档包含信息on changes from previous versions of Jetty session management to the 9.4 style

    如果您点击文档中的链接,您还可以找到有关新会话架构的详细信息。

    正如文档所解释的,当在发行版中运行时,在 jetty-9.4 中配置会话的最简单方法是启用相应的模块。但是,如果您正在运行嵌入式,或者您只想在 xml 中为特定的 webapp 设置会话管理,这里有一些设置 FileSessionDataStore 的示例代码:

    <Get id="sh" name="sessionHandler">
        <Set name="sessionCache">
            <New class="org.eclipse.jetty.server.session.DefaultSessionCache">
              <Arg><Ref id="sh"/></Arg>
              <Set name="sessionDataStore">
                <New class="org.eclipse.jetty.server.session.FileSessionDataStore">
                  <Set name="storeDir">/tmp/sessions</Set>
                </New>
              </Set>
            </New>
        </Set>
    </Get>
    

    【讨论】:

      【解决方案2】:

      啊,我想我解决了,结果不是很好:

      <Set name="sessionHandler">
          <New class="org.eclipse.jetty.server.session.SessionHandler">
          </New>
      </Set>
      
      <Call name="getSessionHandler" id="sessionHandler" />
      
      <Ref refid="sessionHandler">
          <Set name="SessionCache">    
              <New class="org.eclipse.jetty.server.session.DefaultSessionCache">
                  <Arg>
                      <Ref refid="sessionHandler"/>
                  </Arg>
                  <Set name="SessionDataStore">
                      <New class="org.eclipse.jetty.server.session.FileSessionDataStore">
                              <Set name="StoreDir">my/store/path</Set>
                      </New>
                  </Set>
              </New>
          </Set>
      </Ref>
      

      我遵循了在http://useof.org/java-open-source/org.eclipse.jetty.server.session.FileSessionDataStore 找到的更易于阅读的纯 java 示例

      如果 Jetty 专家认为这不正确,我很乐意编辑答案以免误导他人。

      【讨论】:

        猜你喜欢
        • 2020-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多