Versions Compared

Key

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

...

Interface21 added support for session (and request) scoped beans in Spring 2.0. This approach creates a CGLIB or JDK Dynamic proxy of the session scoped bean using the org.springframework.aop.target.scope.ScopedProxyFactoryBean and setting the scopeMap to org.springframework.web.context.scope.SessionScopeMap.

Since the jars are backwards compatible simply build spring (Spring 2.0 M1 should be out by the time you read this.) and use the aop:scope parameters to scope your beans. You can find a .

There are 2 ways to set this up depending upon whether or not XML simplification is used. The first method uses the traditional bean definitions and is useful to understand what is happening under the covers.

A modified applicationContext.xml for the shopping cart example using the traditional XML DTD is below.

Code Block
xml
xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="shoppingCart" class="org.springframework.aop.target.scope.ScopedProxyFactoryBean"
            singleton="false">
        <property name="scopeKey" value="shoppingCart"/>
        <property name="targetBeanName" value="__shoppingCart"/>
        <property name="scopeMap">
            <bean class="org.springframework.web.context.scope.SessionScopeMap"/>
        </property>
    </bean>


    <bean id="__shoppingCart" class="com.opensymphony.webwork.example.ajax.cart.DefaultCart"
            singleton="false"/>

</beans>
{code:xml}

A modified applicationContext.xml for the shopping cart example using the XML simplification is below.

...



{code
xmlxml

: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"
          singleton="true"
          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>

XWork/WebWork specific solutions

...