You are previewing Professional Java™ Development with the Spring Framework.
O'Reilly logo
Professional Java™ Development with the Spring Framework

Book Description

The Spring Framework is a major open source application development framework that makes Java/J2EE(TM) development easier and more productive. This book shows you not only what Spring can do but why, explaining its functionality and motivation to help you use all parts of the framework to develop successful applications.

You will be guided through all the Spring features and see how they form a coherent whole. In turn, this will help you understand the rationale for Spring's approach, when to use Spring, and how to follow best practices. All this is illustrated with a complete sample application. When you finish the book, you will be well equipped to use Spring effectively in everything from simple Web applications to complex enterprise applications.

What you will learn from this book

  • The core Inversion of Control container and the concept of Dependency Injection

  • Spring's Aspect Oriented Programming (AOP) framework and why AOP is important in J2EE development

  • How to use Spring's programmatic and declarative transaction management services effectively

  • Ways to access data using Spring's JDBC functionality, iBATIS SQL Maps, Hibernate, and other O/R mapping frameworks

  • Spring services for accessing and implementing EJBs

  • Spring's remoting framework

Who this book is for

This book is for Java/J2EE architects and developers who want to gain a deeper knowledge of the Spring Framework and use it effectively.

Wrox Professional guides are planned and written by working programmers to meet the real-world needs of programmers, developers, and IT professionals. Focused and relevant, they address the issues technology professionals face every day. They provide examples, practical solutions, and expert education in new technologies, all designed to help programmers do a better job.

Table of Contents

  1. Copyright
  2. About the Authors
  3. Credits
  4. Acknowledgments
  5. Introduction
    1. Whom This Book Is For
    2. Aims of This Book
    3. What This Book Covers
    4. Assumed Knowledge
    5. Recommended Reading
    6. What You Need to Use This Book
    7. The Sample Application
    8. Conventions
    9. Source Code
    10. Errata
    11. p2p.wrox.com
  6. 1. Introducing the Spring Framework
    1. 1.1. Why Spring?
      1. 1.1.1. Problems with the Traditional Approach to J2EE
      2. 1.1.2. Lightweight Frameworks
      3. 1.1.3. Enter Spring
    2. 1.2. Spring's Values
    3. 1.3. Spring in Context
      1. 1.3.1. Technologies
        1. 1.3.1.1. Inversion of Control and Dependency Injection
        2. 1.3.1.2. Aspect-Oriented Programming
        3. 1.3.1.3. Consistent Abstraction
          1. 1.3.1.3.1. Motivation
          2. 1.3.1.3.2. Exceptions
          3. 1.3.1.3.3. Resource Management
      2. 1.3.2. Techniques
      3. 1.3.3. Relationship to Other Frameworks
        1. 1.3.3.1. Persistence Frameworks
        2. 1.3.3.2. Web Frameworks
        3. 1.3.3.3. AOP Frameworks
        4. 1.3.3.4. Other Frameworks
    4. 1.4. Architecting Applications with Spring
      1. 1.4.1. The Big Picture
      2. 1.4.2. Persistence and Integration
        1. 1.4.2.1. Database
        2. 1.4.2.2. Data Access Objects
        3. 1.4.2.3. Persistent Domain Objects
        4. 1.4.2.4. Persistence Technology
      3. 1.4.3. Business Service Objects
      4. 1.4.4. Presentation
        1. 1.4.4.1. Web Tier
        2. 1.4.4.2. Remote Access Facade
        3. 1.4.4.3. Spring RCP
    5. 1.5. The Future
      1. 1.5.1. Release Schedule
      2. 1.5.2. The Evolution of Java and J2EE
      3. 1.5.3. Technology Currents
      4. 1.5.4. Standards and Open Source
    6. 1.6. The Spring Project and Community
      1. 1.6.1. History
      2. 1.6.2. Module Summary
      3. 1.6.3. Supported Environments
    7. 1.7. Summary
  7. 2. The Bean Factory and Application Context
    1. 2.1. Inversion of Control and Dependency Injection
      1. 2.1.1. Different Forms of Dependency Injection
      2. 2.1.2. Deciding Between Setter Injection and Constructor Injection
    2. 2.2. The Container
      1. 2.2.1. The Bean Factory
      2. 2.2.2. The Application Context
      3. 2.2.3. Starting the Container
      4. 2.2.4. Using Beans from the Factory
      5. 2.2.5. XML Bean Configuration
      6. 2.2.6. The Basic Bean Definition
        1. 2.2.6.1. Identifier
        2. 2.2.6.2. Bean Creation Mechanism
        3. 2.2.6.3. Singleton versus Non-Singleton Beans
      7. 2.2.7. Specifying Bean Dependencies
        1. 2.2.7.1. Specifying Bean Dependencies, Detailed
        2. 2.2.7.2. Manual Dependency Declarations
        3. 2.2.7.3. Autowiring Dependencies
        4. 2.2.7.4. Constructor Argument Matching
        5. 2.2.7.5. Validating Bean Dependencies
      8. 2.2.8. Managing the Bean Lifecycle
        1. 2.2.8.1. Initialization and Destruction Callbacks
        2. 2.2.8.2. BeanFactoryAware and ApplicationContextAware Callbacks
      9. 2.2.9. Abstracting Access to Services and Resources
        1. 2.2.9.1. Examining Factory Beans
        2. 2.2.9.2. Key Points and the Net Effect
      10. 2.2.10. Reusing Bean Definitions
        1. 2.2.10.1. Child Bean Definition Specifics
      11. 2.2.11. Using Post-Processors to Handle Customized Beans and Containers
        1. 2.2.11.1. Bean Post-Processors
        2. 2.2.11.2. Bean Factory Post-Processors
        3. 2.2.11.3. PropertyPlaceholderConfigurer
        4. 2.2.11.4. PropertyOverrideConfigurer
        5. 2.2.11.5. CustomEditorConfigurer
          1. 2.2.11.5.1. Creating a Custom PropertyEditor
          2. 2.2.11.5.2. Registering and Using the Custom PropertyEditor
        6. 2.2.11.6. BeanNameAutoProxyCreator
        7. 2.2.11.7. DefaultAdvisorAutoProxyCreator
    3. 2.3. Summary
  8. 3. Advanced Container Concepts
    1. 3.1. Abstractions for Low-Level Resources
      1. 3.1.1. The Application Context as a ResourceLoader
      2. 3.1.2. The Application Context as a Message Source
    2. 3.2. Application Events
    3. 3.3. Managing the Container
      1. 3.3.1. Resource Location Paths in ApplicationContext Constructors
        1. 3.3.1.1. The Special classpath*: Prefix
        2. 3.3.1.2. Ant-Style Paths
      2. 3.3.2. Declarative Usage of Application Contexts
      3. 3.3.3. Splitting Up Container Definitions into Multiple Files
        1. 3.3.3.1. Combining the File Fragments Externally
        2. 3.3.3.2. Combining File Fragments with the Import Element
        3. 3.3.3.3. Combining File Fragments Programmatically
      4. 3.3.4. Strategies for Handling Components
      5. 3.3.5. Singletons for Accessing the Container
    4. 3.4. Some Convenience Factory Beans
      1. 3.4.1. PropertyPathFactoryBean
      2. 3.4.2. FieldRetrievingFactoryBean
      3. 3.4.3. MethodInvokingFactoryBean
    5. 3.5. Property Editors Provided by Spring
    6. 3.6. Strategies for Testing
      1. 3.6.1. Unit Tests
      2. 3.6.2. Tests That Use the Spring Container
        1. 3.6.2.1. Managing the Container Configuration in a Test
        2. 3.6.2.2. In-Appserver Tests
    7. 3.7. Alternatives to XML
      1. 3.7.1. Definitions from Properties Files
      2. 3.7.2. Programmatic Bean Definitions
      3. 3.7.3. Other Formats
    8. 3.8. References
    9. 3.9. Summary
  9. 4. Spring and AOP
    1. 4.1. Goals
    2. 4.2. Assumptions
    3. 4.3. Example
    4. 4.4. Spring's AOP Framework
      1. 4.4.1. The Interceptor Chain
      2. 4.4.2. Pros and Cons
      3. 4.4.3. Advice
        1. 4.4.3.1. The AOP Alliance
          1. 4.4.3.1.1. Method Interceptors
        2. 4.4.3.2. Spring Advice Types
          1. 4.4.3.2.1. Before Advice
          2. 4.4.3.2.2. After Returning Advice
          3. 4.4.3.2.3. Throws Advice
          4. 4.4.3.2.4. Other Advice Types
      4. 4.4.4. Pointcuts
        1. 4.4.4.1. Spring Pointcut Concepts
        2. 4.4.4.2. The Pointcut Interface and Friends
        3. 4.4.4.3. Static and Dynamic Pointcuts
        4. 4.4.4.4. Pointcuts Shipped with Spring
          1. 4.4.4.4.1. Pointcut Constants
          2. 4.4.4.4.2. NameMatchMethodPointcut
          3. 4.4.4.4.3. Regular Expression Pointcuts
          4. 4.4.4.4.4. ControlFlowPointcut
          5. 4.4.4.4.5. StaticMethodMatcherPointcut Base Class
          6. 4.4.4.4.6. DynamicMethodMatcherPointcut Base Class
        5. 4.4.4.5. Operating on Pointcuts
      5. 4.4.5. Advisors
        1. 4.4.5.1. Advisor Implementations
        2. 4.4.5.2. DefaultPointcutAdvisor
        3. 4.4.5.3. Regular Expressions, Take 2
        4. 4.4.5.4. Wrapping
      6. 4.4.6. Integration with the Spring IoC Container
        1. 4.4.6.1. Basic Proxy Configuration
        2. 4.4.6.2. Using ProxyFactoryBean
          1. 4.4.6.2.1. Basic Concepts
          2. 4.4.6.2.2. Simplifying Configuration When Using ProxyFactoryBean
        3. 4.4.6.3. Understanding the Lifecycle of Objects
        4. 4.4.6.4. Autoproxying
          1. 4.4.6.4.1. BeanNameAutoProxyCreator
          2. 4.4.6.4.2. DefaultAdvisorAutoProxyCreator
          3. 4.4.6.4.3. Configuration Options
          4. 4.4.6.4.4. Attribute-Driven Autoproxying
        5. 4.4.6.5. Advanced Autoproxy Creation
        6. 4.4.6.6. Making a Choice
      7. 4.4.7. Examining and Manipulating Proxy State at Runtime
      8. 4.4.8. Programmatic Proxy Creation
    5. 4.5. Using Advanced Features of Spring's AOP Framework
      1. 4.5.1. TargetSources
        1. 4.5.1.1. HotSwappableTargetSource
        2. 4.5.1.2. Pooling Target Source
          1. 4.5.1.2.1. Use Out of the Box
          2. 4.5.1.2.2. Use with Your Own Choice of Pooling Implementation
          3. 4.5.1.2.3. When Should You Use Pooling?
          4. 4.5.1.2.4. Exposing Pool Statistics
        3. 4.5.1.3. Custom TargetSources
          1. 4.5.1.3.1. Programmatic Access to the TargetSource
        4. 4.5.1.4. Doing Without a Target Object
      2. 4.5.2. Terminating the Interceptor Chain Early
      3. 4.5.3. Using Introduction
      4. 4.5.4. Exposing the Current Proxy
      5. 4.5.5. Exposing the Current MethodInvocation
      6. 4.5.6. Understanding Proxy Types
      7. 4.5.7. Debugging and Testing
      8. 4.5.8. Miscellaneous
        1. 4.5.8.1. Changing Method Arguments
        2. 4.5.8.2. Double Proxying
        3. 4.5.8.3. Implementing Multiple AOP Framework Interfaces
        4. 4.5.8.4. Serializing AOP Proxies
        5. 4.5.8.5. Invoking proceed() More Than Once
    6. 4.6. Integration with Other AOP Frameworks
      1. 4.6.1. Goals
      2. 4.6.2. AspectJ Integration
        1. 4.6.2.1. Using Dependency Injection to Configure AspectJ Aspects
          1. 4.6.2.1.1. Singleton Aspects
          2. 4.6.2.1.2. More Advanced Usages
          3. 4.6.2.1.3. Scoping Issues
          4. 4.6.2.1.4. Understanding Aspect Association
        2. 4.6.2.2. Choosing Between Spring AOP and AspectJ
      3. 4.6.3. AspectWerkz
    7. 4.7. References
    8. 4.8. Summary
  10. 5. DAO Support and JDBC Framework
    1. 5.1. The Data Access Object Pattern
    2. 5.2. Introducing Spring's JDBC Framework
      1. 5.2.1. Motivation: Issues with Direct Use of JDBC
        1. 5.2.1.1. Managing the Connection, Statements, and ResultSets
        2. 5.2.1.2. Handling SQLExceptions
        3. 5.2.1.3. Lookup of Resources
        4. 5.2.1.4. JDBC Strengths
          1. 5.2.1.4.1. Implementations Provided by Vendors
          2. 5.2.1.4.2. Using SQL
          3. 5.2.1.4.3. Cross Database Escape Syntax
      2. 5.2.2. How Spring Can Help
      3. 5.2.3. A Simple Example
    3. 5.3. Building the Data Access Layer for the Sample Application
      1. 5.3.1. Data Model for the Sample Application
      2. 5.3.2. DataSource
      3. 5.3.3. Exception Translation
    4. 5.4. Operations with JdbcTemplate
      1. 5.4.1. Use of Callback Methods
      2. 5.4.2. JdbcTemplate Convenience Methods
      3. 5.4.3. Basic Queries Using the JdbcTemplate
      4. 5.4.4. Basic Updating with JdbcTemplate
      5. 5.4.5. Advanced Use of JdbcTemplate
      6. 5.4.6. Support for RowSet
    5. 5.5. Using the RDBMS Operation Classes
      1. 5.5.1. SqlQuery and MappingSqlQuery
      2. 5.5.2. Inserts and Updates with SqlUpdate
      3. 5.5.3. Updating a ResultSet Using UpdatableSqlQuery
      4. 5.5.4. Generating Primary Keys
      5. 5.5.5. Retrieving Database-Generated Keys
      6. 5.5.6. Calling a Stored Procedure
    6. 5.6. Advanced Concepts
      1. 5.6.1. Running Spring JDBC in an Application Server
        1. 5.6.1.1. Connection Pooling
        2. 5.6.1.2. Connection and Statement Wrappers
      2. 5.6.2. Using Custom Exception Translations
        1. 5.6.2.1. Providing a CustomSQLErrorCodesTranslation
        2. 5.6.2.2. Implementing an SQLErrorCodeSQLExceptionTranslator
      3. 5.6.3. Reading and Writing LOB Data
        1. 5.6.3.1. Using the JdbcTemplate for LOB Access
        2. 5.6.3.2. Using the RDBMS Operation LOB Support
        3. 5.6.3.3. Using LobHandler and JdbcExtractor Together
      4. 5.6.4. Batch Updates
      5. 5.6.5. Advanced Use of Stored Procedures
        1. 5.6.5.1. Passing in a Complex Type as a Parameter
        2. 5.6.5.2. Returning a ResultSet
    7. 5.7. Additional Considerations
      1. 5.7.1. Performance
      2. 5.7.2. When to Use JDBC Versus O/R Mapping
      3. 5.7.3. JDBC Versions and J2EE Versions
    8. 5.8. Summary
  11. 6. Transaction and Resource Management
    1. 6.1. Background
      1. 6.1.1. What Is a Transaction?
      2. 6.1.2. The ACID Properties
        1. 6.1.2.1. Atomicity
        2. 6.1.2.2. Isolation
      3. 6.1.3. Concurrency Control
        1. 6.1.3.1. Pessimistic Locking
        2. 6.1.3.2. Optimistic Locking
    2. 6.2. Transactions and J2EE
      1. 6.2.1. Local Transactions
      2. 6.2.2. Global/Distributed Transactions
      3. 6.2.3. Transaction Propagation
      4. 6.2.4. Transaction Demarcation
        1. 6.2.4.1. Programmatic Transaction Management
        2. 6.2.4.2. Declarative Transactions
    3. 6.3. An Example of Spring's Transaction Support
    4. 6.4. Introducing Spring's Transaction Abstraction
      1. 6.4.1. Overview of Choices for Transaction Control
      2. 6.4.2. Transaction Definition
        1. 6.4.2.1. Propagation Behavior
        2. 6.4.2.2. Isolation
        3. 6.4.2.3. Timeout
        4. 6.4.2.4. Read-Only
      3. 6.4.3. Transaction Status
      4. 6.4.4. Transaction Demarcation Strategies
        1. 6.4.4.1. Where to Demarcate Transactions
        2. 6.4.4.2. Programmatic Transaction Demarcation
          1. 6.4.4.2.1. Direct Programmatic Use of PlatformTransactionManager
          2. 6.4.4.2.2. TransactionTemplate
        3. 6.4.4.3. Declarative Transaction Demarcation
          1. 6.4.4.3.1. ProxyFactoryBean/Transaction Interceptor
          2. 6.4.4.3.2. TransactionProxyFactoryBean
          3. 6.4.4.3.3. BeanNameAutoProxyCreator
          4. 6.4.4.3.4. Source-Level Metadata Using Commons Attributes
          5. 6.4.4.3.5. Source-Level Metadata Using J2SE 5.0 Annotations
        4. 6.4.4.4. Performance Implications
        5. 6.4.4.5. Transaction Demarcation Best Practices
      5. 6.4.5. Transaction Management Strategies
        1. 6.4.5.1. Single Resource Transaction Managers
          1. 6.4.5.1.1. DataSourceTransactionManager
          2. 6.4.5.1.2. HibernateTransactionManager
          3. 6.4.5.1.3. JDOTransactionManager
          4. 6.4.5.1.4. TopLinkTransactionManager
          5. 6.4.5.1.5. PersistenceBrokerTransactionManager
        2. 6.4.5.2. JtaTransactionManager
          1. 6.4.5.2.1. Application Server–Specific JTA Configuration
          2. 6.4.5.2.2. Considerations for JTA and O/R Mapping
    5. 6.5. DataSource Declarations
      1. 6.5.1. Local Unpooled
      2. 6.5.2. Local Pooled
      3. 6.5.3. JNDI
      4. 6.5.4. Choosing Between Local and JNDI DataSource
    6. 6.6. Summary
  12. 7. Object/Relational Mapping
    1. 7.1. Background
      1. 7.1.1. Basic O/R Mapping
      2. 7.1.2. Object Query Languages
      3. 7.1.3. Transparent Persistence
      4. 7.1.4. When to Choose O/R Mapping
    2. 7.2. O/R Mapping Support in Spring
      1. 7.2.1. Data Access Objects
      2. 7.2.2. Transaction Management
    3. 7.3. iBATIS SQL Maps
      1. 7.3.1. Mapping File
      2. 7.3.2. DAO Implementation
      3. 7.3.3. Setup in a Spring Context
      4. 7.3.4. Transaction Management
      5. 7.3.5. iBATIS Summary
    4. 7.4. Hibernate
      1. 7.4.1. Mapping File
      2. 7.4.2. DAO Implementation
      3. 7.4.3. Setup in a Spring Context
        1. 7.4.3.1. Setup as a JCA Connector
      4. 7.4.4. Transaction Management
        1. 7.4.4.1. JTA Synchronization
        2. 7.4.4.2. Session Lifecycle
        3. 7.4.4.3. Reattachment and the Duplicate Object Problem
        4. 7.4.4.4. HibernateInterceptor
      5. 7.4.5. Open Session in View
        1. 7.4.5.1. Single Session Versus Deferred Close
        2. 7.4.5.2. Configuration Examples
      6. 7.4.6. BLOB/CLOB Handling
      7. 7.4.7. Hibernate: Summary
    5. 7.5. JDO
      1. 7.5.1. Persistent Object Lifecycle
      2. 7.5.2. DAO Implementation
      3. 7.5.3. Setup in a Spring Context
      4. 7.5.4. Transaction Management
      5. 7.5.5. PersistenceManager Lifecycle
      6. 7.5.6. Open PersistenceManager in View
        1. 7.5.6.1. Configuration Examples
      7. 7.5.7. JDO Dialect
      8. 7.5.8. JDO: Summary
    6. 7.6. Other O/R Mapping Tools
      1. 7.6.1. Apache OJB
      2. 7.6.2. TopLink
      3. 7.6.3. Cayenne
      4. 7.6.4. JSR-220 Persistence
    7. 7.7. Summary
  13. 8. Lightweight Remoting
    1. 8.1. Concepts and Scope
    2. 8.2. Common Configuration Style
    3. 8.3. Hessian and Burlap
      1. 8.3.1. Accessing a Service
      2. 8.3.2. Exporting a Service
    4. 8.4. HTTP Invoker
      1. 8.4.1. Accessing a Service
      2. 8.4.2. Exporting a Service
      3. 8.4.3. Customization Options
    5. 8.5. RMI
      1. 8.5.1. Accessing a Service
      2. 8.5.2. Stub Lookup Strategies
      3. 8.5.3. Exporting a Service
      4. 8.5.4. Customization Options
      5. 8.5.5. RMI-IIOP
    6. 8.6. Web Services via JAX-RPC
      1. 8.6.1. Accessing a Service
      2. 8.6.2. Exporting a Service
      3. 8.6.3. Custom Type Mappings
    7. 8.7. Summary
  14. 9. Supporting Services
    1. 9.1. JMS
      1. 9.1.1. Introduction
      2. 9.1.2. Motivation for Spring's JMS Support
      3. 9.1.3. JMS Access via a Template
        1. 9.1.3.1. Callback Methods
        2. 9.1.3.2. Synchronous Receiving
        3. 9.1.3.3. Quality of Service Parameters
      4. 9.1.4. Exception Handling
      5. 9.1.5. ConnectionFactory Management
      6. 9.1.6. Message Converters
      7. 9.1.7. Destination Management
      8. 9.1.8. Transaction Management
      9. 9.1.9. JmsGatewaySupport
      10. 9.1.10. The Future
    2. 9.2. Scheduling with Spring
      1. 9.2.1. Timers Versus Quartz
      2. 9.2.2. Timers
      3. 9.2.3. Quartz
        1. 9.2.3.1. Job
        2. 9.2.3.2. JobDetail
        3. 9.2.3.3. Trigger
        4. 9.2.3.4. Scheduler
    3. 9.3. Sending Email with Spring
      1. 9.3.1. Getting Started
      2. 9.3.2. Reusing an Existing Mail Session
      3. 9.3.3. Mail Sending Using COS
      4. 9.3.4. Generic Mail Manager
        1. 9.3.4.1. Message Creation
        2. 9.3.4.2. Recipients
        3. 9.3.4.3. Content
        4. 9.3.4.4. Attachments
        5. 9.3.4.5. Sending
    4. 9.4. Scripting
      1. 9.4.1. Consistent Model
        1. 9.4.1.1. Groovy
        2. 9.4.1.2. Beanshell
      2. 9.4.2. Other Scripting Languages
    5. 9.5. Summary
  15. 10. Acegi Security System for Spring
    1. 10.1. Enterprise Application Security Choices
      1. 10.1.1. Typical Requirements
      2. 10.1.2. Acegi Security in a Nutshell
        1. 10.1.2.1. Authentication
        2. 10.1.2.2. Web Request Security
        3. 10.1.2.3. Service Layer Security
        4. 10.1.2.4. Domain Object Instance Security
      3. 10.1.3. Java Authentication and Authorization Service
      4. 10.1.4. Servlet Specification
    2. 10.2. Acegi Security Fundamentals
      1. 10.2.1. Authentication
      2. 10.2.2. Storing the Authentication Object
      3. 10.2.3. Authorization
      4. 10.2.4. Domain Object Instance Security
    3. 10.3. Example Code
      1. 10.3.1. Introducing the Sample
      2. 10.3.2. Security Unaware Implementation
      3. 10.3.3. Security Approach
      4. 10.3.4. Authentication
      5. 10.3.5. Authorization
    4. 10.4. Summary
  16. 11. Spring and EJB
    1. 11.1. Deciding on the Need for EJBs
    2. 11.2. Accessing EJBs
      1. 11.2.1. The Boilerplate Approach
      2. 11.2.2. The Spring Approach
        1. 11.2.2.1. Encapsulating the Home Object Lookup
        2. 11.2.2.2. Encapsulating Stateless Session Bean Lookups
          1. 11.2.2.2.1. Accessing Local EJBs
          2. 11.2.2.2.2. Accessing Remote EJBs
          3. 11.2.2.2.3. Accessing Remote EJBs, Unifying the Business Interface
    3. 11.3. Implementing EJBs with Spring
      1. 11.3.1. Stateless Session Beans
      2. 11.3.2. Stateful Session Beans
      3. 11.3.3. Message Driven Beans
      4. 11.3.4. A Digression into XDoclet
    4. 11.4. Singleton Container Access, Good or Evil?
      1. 11.4.1. ContextSingletonBeanFactoryLocator and SingletonBeanFactoryLocator
      2. 11.4.2. A Shared Context as the Parent of a Web-App Application Context
      3. 11.4.3. Using a Shared Context from EJBs
    5. 11.5. Testing Concerns
      1. 11.5.1. Implement Business Functionality in POJO Delegate
      2. 11.5.2. Use a Mock EJB Container
      3. 11.5.3. Integration Testing Inside the AppServer
    6. 11.6. Summary
  17. 12. Web MVC Framework
    1. 12.1. A Simple Example
    2. 12.2. General Architecture
      1. 12.2.1. Web MVC Concepts
      2. 12.2.2. Generic Web MVC Using a Dispatcher and Controllers
      3. 12.2.3. Requirements for a Good Web MVC Framework
      4. 12.2.4. Spring's Web MVC Equivalents
        1. 12.2.4.1. Executing Actions in Controllers
        2. 12.2.4.2. Returning a ModelAndView
        3. 12.2.4.3. Rendering a View
        4. 12.2.4.4. Completing the Picture: The DispatcherServlet
    3. 12.3. Infrastructural Components
      1. 12.3.1. The DispatcherServlet
      2. 12.3.2. The WebApplicationContext
    4. 12.4. Workflow Involved with Handling Requests
    5. 12.5. Common Layout of a Spring MVC Web Application
    6. 12.6. HandlerMappings
      1. 12.6.1. BeanNameUrlHandlerMapping
      2. 12.6.2. SimpleUrlHandlerMapping
      3. 12.6.3. CommonsPathMapUrlHandlerMapping
      4. 12.6.4. More Than One HandlerMapping
    7. 12.7. HandlerExecutionChain and Interceptors
      1. 12.7.1. WebContentInterceptor
      2. 12.7.2. UserRoleAuthorizationInterceptor
      3. 12.7.3. Other Handler Interceptors Provided by Spring MVC
    8. 12.8. Handlers and Their Adapters
    9. 12.9. ModelAndView and ViewResolvers
      1. 12.9.1. UrlBasedViewResolvers
      2. 12.9.2. BeanNameViewResolver and XmlViewResolver
      3. 12.9.3. ResourceBundleViewResolver
      4. 12.9.4. Chaining View Resolvers
        1. 12.9.4.1. Overriding One Specific View
        2. 12.9.4.2. Disabling View Resolver Chaining
    10. 12.10. Locale Changing and Resolution
    11. 12.11. HandlerExceptionResolvers
    12. 12.12. Controllers
      1. 12.12.1. WebContentGenerator
      2. 12.12.2. AbstractController
      3. 12.12.3. UrlFilenameViewController
      4. 12.12.4. ParameterizableViewController
      5. 12.12.5. MultiActionController
    13. 12.13. Data Binding
      1. 12.13.1. Convenient Functionality When Working with Data Binding
        1. 12.13.1.1. Checkboxes and Radio Buttons
        2. 12.13.1.2. Indexed and Mapped Properties: Maps, Lists, and Arrays
    14. 12.14. Real-World Examples of Using Controllers
      1. 12.14.1. Viewing a List of Performances Using the AbstractController
        1. 12.14.1.1. Workflow of the ViewShowController
        2. 12.14.1.2. Implementing the Controller
        3. 12.14.1.3. Wiring Up the Controller
      2. 12.14.2. Making a Reservation
        1. 12.14.2.1. SimpleFormController
          1. 12.14.2.1.1. Properties to Configure the Controller With
          2. 12.14.2.1.2. Callbacks and Template Methods for Custom Behavior
          3. 12.14.2.1.3. Form Workflow
    15. 12.15. Wizard Functionality
      1. 12.15.1. Basic Configuration
      2. 12.15.2. Template Methods
      3. 12.15.3. Flow of a Wizard
      4. 12.15.4. Page Changes, Numbering, and Other Actions
    16. 12.16. Extending Spring's Handler Infrastructure
    17. 12.17. Uploading Files
      1. 12.17.1. Configuring the Multipart Resolver
      2. 12.17.2. Creating a Form to Upload a File
      3. 12.17.3. Handling Uploaded Data
    18. 12.18. Testing Your Controllers
      1. 12.18.1. Testing Without the Application Context
      2. 12.18.2. More Extensive Testing Using Mock Objects
      3. 12.18.3. Testing Using the Complete Application Context
      4. 12.18.4. Other Ways to Test a Web Application
    19. 12.19. Summary
  18. 13. Web View Technologies
    1. 13.1. An Example
      1. 13.1.1. General Configuration
      2. 13.1.2. JavaServer Pages
      3. 13.1.3. FreeMarker
      4. 13.1.4. Generating PDFs Using iText
    2. 13.2. Considerations When Choosing a Technology
    3. 13.3. View Objects and Models
    4. 13.4. Features Offered by the AbstractView
      1. 13.4.1. Issuing a New Request Using the RedirectView
      2. 13.4.2. Using View Prefixes to Issue Forwards or Redirects
    5. 13.5. JavaServer Pages
      1. 13.5.1. Configuring Your Application to Use JSP
      2. 13.5.2. Creating Forms Using Custom Tags
        1. 13.5.2.1. BindStatus and spring:bind
        2. 13.5.2.2. spring:nestedPath
        3. 13.5.2.3. spring:transform
        4. 13.5.2.4. spring:message
        5. 13.5.2.5. A Final Note on Spring Tags
      3. 13.5.3. Using Tag Files to Create Reusable Elements
    6. 13.6. Velocity and FreeMarker
      1. 13.6.1. Configuring the View Resolver
        1. 13.6.1.1. Configuring Velocity
        2. 13.6.1.2. Configuring FreeMarker
      2. 13.6.2. Using the Form Simplification Macros
        1. 13.6.2.1. Configuring Your FreeMarker and Velocity Templates to Use Macros
        2. 13.6.2.2. Using Velocity or FreeMarker Macros to Create a Form
    7. 13.7. Tiles
    8. 13.8. Views Based on XML and XSLT
    9. 13.9. Excel and Other Document-Based Views
      1. 13.9.1. Generating an Excel File from Our List of Shows
      2. 13.9.2. Using a Template as a Basis for Your Excel File
      3. 13.9.3. Other Document-Based Views
      4. 13.9.4. Using a HandlerInterceptor to Distinguish Between HTML and Excel
    10. 13.10. Implementing Custom Views
      1. 13.10.1. View and AbstractView
      2. 13.10.2. Implementing a View Generating XML from a Data Object
      3. 13.10.3. Considerations When Implementing Custom Views
    11. 13.11. Summary
  19. 14. Integrating with Other Web Frameworks
    1. 14.1. Considerations When Choosing an MVC Framework
      1. 14.1.1. Comparing the Traditional Web MVC Frameworks
        1. 14.1.1.1. Data Binding and Validation
          1. 14.1.1.1.1. WebWork
          2. 14.1.1.1.2. Struts
          3. 14.1.1.1.3. Spring MVC
          4. 14.1.1.1.4. Tapestry
          5. 14.1.1.1.5. JavaServer Faces
        2. 14.1.1.2. Dealing with the Presentation Layer
          1. 14.1.1.2.1. WebWork
          2. 14.1.1.2.2. Struts
          3. 14.1.1.2.3. Spring MVC
          4. 14.1.1.2.4. Tapestry
          5. 14.1.1.2.5. JavaServer Faces
        3. 14.1.1.3. Controller Infrastructure and Interception Handling
          1. 14.1.1.3.1. WebWork
          2. 14.1.1.3.2. Struts
          3. 14.1.1.3.3. Spring MVC
          4. 14.1.1.3.4. Tapestry
          5. 14.1.1.3.5. JavaServer Faces
        4. 14.1.1.4. Other Characteristics
          1. 14.1.1.4.1. WebWork
          2. 14.1.1.4.2. Struts
          3. 14.1.1.4.3. Spring Web MVC
          4. 14.1.1.4.4. Tapestry
          5. 14.1.1.4.5. JavaServer Faces
    2. 14.2. Integrating with Spring: Core Concepts
    3. 14.3. WebWork Integration
      1. 14.3.1. Setting Up the ObjectFactory
    4. 14.4. Struts Integration
      1. 14.4.1. Using ActionSupport
      2. 14.4.2. Using DelegationRequestProcessor and DelegationActionProxy
        1. 14.4.2.1. Defining the Struts ActionServlet and the ContextLoaderPlugIn
      3. 14.4.3. Using an Auto Wiring Base Action
    5. 14.5. Tapestry Integration
      1. 14.5.1. Getting Beans for Tapestry
      2. 14.5.2. The Page Class
      3. 14.5.3. The Page Definition
      4. 14.5.4. The Page Template
      5. 14.5.5. Tapestry Integration Final Thoughts
    6. 14.6. JavaServer Faces Integration
    7. 14.7. Summary
  20. 15. The Sample Application
    1. 15.1. Choice of Server Technologies
    2. 15.2. Application Layers
    3. 15.3. Persistence Layer
      1. 15.3.1. Data Model
      2. 15.3.2. Domain Object Model
      3. 15.3.3. Object/Relational Mapping
      4. 15.3.4. DAO Implementation
      5. 15.3.5. Data Access Context
    4. 15.4. Business Service Layer
      1. 15.4.1. Services
      2. 15.4.2. Application Context
    5. 15.5. Web Layer
      1. 15.5.1. Flow Through the Application
      2. 15.5.2. Configuring the Application via web.xml
      3. 15.5.3. Web Controllers
      4. 15.5.4. View Technology
    6. 15.6. Comparison with the J2EE Design and Development Implementation
      1. 15.6.1. Simpler Technology
      2. 15.6.2. Database Changes
    7. 15.7. Server Configuration
      1. 15.7.1. MySQL
      2. 15.7.2. Tomcat
    8. 15.8. Build and Deployment
      1. 15.8.1. Creating and Loading the Database Tables
      2. 15.8.2. Building the Application and Deploying It to the Tomcat Server
    9. 15.9. Summary
  21. 16. Conclusion
    1. 16.1. Problems Solved by Spring
    2. 16.2. The Spring Solution
    3. 16.3. Guidelines for Spring Development
      1. 16.3.1. Technology Choices
        1. 16.3.1.1. Spring Versus "Old J2EE"
        2. 16.3.1.2. Distributed Versus Local Objects
        3. 16.3.1.3. Java Versus Other Languages?
      2. 16.3.2. Layer by Layer
        1. 16.3.2.1. A Layered Architecture
        2. 16.3.2.2. Data Access and Integration
        3. 16.3.2.3. Persistent Domain Model
        4. 16.3.2.4. Business Services Layer
          1. 16.3.2.4.1. Transaction Management
          2. 16.3.2.4.2. Threading Issues
        5. 16.3.2.5. Presentation Tier
          1. 16.3.2.5.1. Web Application Presentation
          2. 16.3.2.5.2. Remoting
      3. 16.3.3. Structuring Applications
        1. 16.3.3.1. Overall Issues
        2. 16.3.3.2. Spring Configuration Issues
          1. 16.3.3.2.1. Different Styles of Dependency Injection
          2. 16.3.3.2.2. Autowiring
          3. 16.3.3.2.3. Autoproxying
          4. 16.3.3.2.4. Inheritance of Bean Definitions
          5. 16.3.3.2.5. Breaking Up Configuration
        3. 16.3.3.3. What Should Be an Aspect?
      4. 16.3.4. Testing Your Applications
        1. 16.3.4.1. Unit Testing
        2. 16.3.4.2. In-Context Integration Testing
        3. 16.3.4.3. Higher Levels of Testing
    4. 16.4. Related Projects
      1. 16.4.1. Acegi Security for Spring
      2. 16.4.2. Other Projects
    5. 16.5. Spring in Non-J2EE Environments
    6. 16.6. To Find Out More
      1. 16.6.1. Books and Articles
      2. 16.6.2. Online Resources
      3. 16.6.3. Sample Applications
        1. 16.6.3.1. jPetStore
        2. 16.6.3.2. PetClinic
        3. 16.6.3.3. ImageDB
    7. 16.7. The Future
  22. A. Requirements for the Sample Application
    1. A.1. Overview
    2. A.2. User Populations
      1. A.2.1. Public Internet Users
      2. A.2.2. Box Office Users
      3. A.2.3. Administrators
    3. A.3. Assumptions
    4. A.4. Scope Limitations
    5. A.5. Delivery Schedule
    6. A.6. Internet User Interface
      1. A.6.1. Basic Workflow
      2. A.6.2. Error Handling
      3. A.6.3. Application Screens
        1. A.6.3.1. Welcome Screen
        2. A.6.3.2. Display Show Screen
        3. A.6.3.3. Book Seats Screen
        4. A.6.3.4. Show Reservation Screen
        5. A.6.3.5. Payment Details Screen
        6. A.6.3.6. Confirm Reservation Screen
        7. A.6.3.7. Box Office User Interface
    7. A.7. Non-Functional Requirements
    8. A.8. Hardware and Software Environment