开发者

How to persist sessions with Jetty 7 and jetty-maven-plugin?

I'd like to configure Jetty to persist sessions on disk, so that restarting Jetty would not lose the sessions, but by reading 开发者_如何学编程the documentation I haven't yet got it working.

I'm running Jetty using Jetty Maven plugin (org.mortbay.jetty:jetty-maven-plugin 7.4.3.v20110701).

Enabling Persistence for the Maven Jetty Plugin tells to set up the HashSessionManager in the sessionHandler configuration section of the plugin, but the example there seems to be for the old maven-jetty-plugin, not the new jetty-maven-plugin.

I tried fixing the class names there like this (I also had to add a dependency to jetty-server jar, otherwise I got ClassNotFoundExceptions):

<webAppConfig implementation="org.mortbay.jetty.plugin.JettyWebAppContext">
    <defaultsDescriptor>${project.build.outputDirectory}/META-INF/webdefault.xml</defaultsDescriptor>
    <contextPath>${jetty.contextRoot}</contextPath>
    <sessionHandler implementation="org.eclipse.jetty.server.session.SessionHandler">
        <sessionManager implementation="org.eclipse.jetty.server.session.HashSessionManager">
            <storeDirectory>${basedir}/target/jetty-sessions</storeDirectory>
        </sessionManager>
    </sessionHandler>
</webAppConfig>

Directory target/jetty-sessions gets created when server is run, but nothing is written there and the sessions don't persist as far as I can tell.

So, what am I missing?


The documentation lists the wrong class names. Use this snippet:

<sessionHandler implementation="org.eclipse.jetty.server.session.SessionHandler">
  <sessionManager implementation="org.eclipse.jetty.server.session.HashSessionManager">
    <storeDirectory>${basedir}/target/sessions</storeDirectory>
    <idleSavePeriod>1</idleSavePeriod>
  </sessionManager>
</sessionHandler>

I don't have an Eclipse login to fix it on their wiki. Maybe you can grab one and fix it there too to help others.

Update: I added idleSavePeriod to the configuration. I first thought you just copied the typo from Eclipse wiki.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜