Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Motivation

Spring currently does currently not support session scoped beans/components out of the box. You can decide between singleton or prototype lifecycle, but not having you cannot have your beans bound to the session lifecycle of web applications. There are plans for integrating such a feature in the Spring 12.3 release, but this is not confirmed and there is no schedule0 release.
We will try to point out some possible workarounds for your webwork WebWork based applications. First we look at the general solutions found among the Spring community, dealing with HTTPSession and all that. After that we will discuss the special conditions and requirements found in XWork/WebWork and how that might affect possible solutions. We will show some XWork/WebWork specific solutions for the given problem.

...

Code Block
xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

    <bean id="catalog" class="com.opensymphony.webwork.example.ajax.catalog.TestCatalog"
          singleton="true"/>

    <bean id="shoppingCart" class="com.opensymphony.webwork.example.ajax.cart.DefaultCart">
        <aop:scope type="session"/>
    </bean>

</beans>

Also You will also need to modify the web.xml to include the following filter.

...

WebWork is based on XWork, and XWork is not tied to the web layer. So when dealing with session scoped stuffobjects, WW users might want to use XWorks XWork's session abstraction features to keep their application independent from the web context. This is why we will discuss some XW/WW specific solutions below.

...

Here is a modified version of the TargetSource solution pointed out above that integrates with the existing WebWork session so and doesn't require an additional filter or listener. Usage is pretty much the same, create an interface for your object and make sure that you always use that interface and not the underlying implementation or autowiring will fail. You can find more information on how to make this work by looking at the WebWorkTargetSource Shopping Cart Example.

...