Expert Spring MVC and Web Flow

(Dana P.) #1

This means for any nontrivial web application, request scope is too fine grained and ses-
sion scope is not fine grained enough.
Why not store everything in the session and manually perform cleanups when the con-
versation ends? To begin, there are many well-documented issues associated with storing
context within the session, including (but not limited to):



  • Server affinity. If your application is to be deployed into a clustered environment,
    then your clients will suffer from server affinity. This occurs because a user’s session
    is unique to each server, so if a user connects to another server, he will receive a whole
    new session. Server affinity prevents failover (http://en.wikipedia.org/wiki/Failover),
    thus reducing your ability to load balance within a cluster.


■NoteThere are solutions for session replication in clustered environment, but they are typically
very expensive and complex, and they always incur some performance overhead.


  • Greatly increased memory footprint per user.Because each user’s session is stored in
    memory, the serving capacity of each server is reduced. This is compounded by the fact
    that out-of-date context (e.g., ended or expired conversations) still exists in the session
    and needs to be manually removed.

  • Name space clashes. Assuming context for a user registration use case is stored in the
    session under the name “registration,” what happens if any given user tries to register
    more than one user at the same time using multiple browser windows or tabs? The data
    will overwrite itself. In summary, the concept of a conversation scope is a missing piece
    of the Servlet specification. The life span of conversational scope is longer than a
    request but shorter than a session. It has an explicit beginning and an end that corre-
    sponds to the time to complete or cancel an application transaction that spans one or
    more requests into the server.

  • No vocabulary for process modeling. The absence of conversational scope introduces a
    mismatch between modeling and implementation. Process modeling is not concerned
    with individual pages or the concept of a session that encapsulates the browser’s entire
    interaction with the server. Instead, it focuses on modeling one or more business goals
    of a system. The current Servlet specification (and modern MVC implementations) do
    not provide implementation constructs, or vocabularly that engineer naturally to and
    from a process model.


The Solution


So how does Spring Web Flow help?


The Flow Is King


Firstly, Spring Web Flow treats conversational scope as a first-level citizen. It was designed
from the ground up with that as the centerpiece. The core artifact within Spring Web Flow is
the flow(or conversation). It is this flow definitionthat defines a blueprint for a conversation


CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW 311
Free download pdf