July 17, 2014

Save Session State Between Redeploys - Developing on WildFly

When developing, it is often convenient to save session state between redeploys or server restarts. To enable this feature in WildFly 8 you need to add the persistent-sessions element to your configuration file (within the undertow subsystem).

<servlet-container name="default">
    <persistent-sessions path="session" relative-to="jboss.server.temp.dir"/>
    <jsp-config/>
</servlet-container>
By specifying the relative-to attribute, the session will only be persistent across redeploys and not across server restarts.

This feature works in WildFly 8.2.0.CR1 and greater.

You can also achieve session passivation, when you are using a non-ha profile, by adding <distributable/> to your web.xml (for those using WildFly 8.1.0 or less).

1 comment :

  1. "By specifying the relative-to attribute, the session will only be persistent across redeploys and not across server restarts."

    Actually, I think the docs indicate it is exactly the other way around:

    "If the path is not specified then session data is stored in memory, and will only be persistent across redeploys, rather than restarts."

    If you do NOT specify a path, the session data is not stored on disk but in memory, so will not survive server restarts. This makes sense. The docs only mention this about relative-to:

    "The location that the path is relevant to"

    Should read *relative* to... But there is nothing here indicating that specifying relative-to would have an effect on sessions not being persisted across restarts.

    Docs: https://docs.jboss.org/author/display/WFLY8/Undertow+subsystem+configuration

    ReplyDelete