You are previewing Pro Spring 2.5.
O'Reilly logo
Pro Spring 2.5

Book Description

The move from so-called heavyweight architectures, such as Enterprise JavaBeans, toward lightweight frameworks, like Spring, has not stopped since Pro Spring was published by Rob Harrop and Jan Machacek in 2005; in fact, it's picked up pace. The Spring Framework remains the leader in this move and provides a platform on which you can build your own applications and services.

Pro Spring 2.5 covers the new features of Spring 2.5, but moreover, it is focused on the best practices and core standards of contemporary Spring development. As members of the Spring development team at Cake Solutions, the author team brings extensive practical experience gained from working with Spring since version 1.0 and delivering successful systems on top of it.

Table of Contents

  1. Copyright
  2. Foreword
  3. About the Authors
  4. About the Technical Reviewer
  5. Acknowledgments
  6. Introduction
  7. I. Getting Started with Spring
    1. 1. Introducing Spring
      1. What Is Spring?
        1. Beyond Dependency Injection
        2. Aspect-Oriented Programming with Spring
        3. Accessing Data in Spring
        4. Simplifying and Integrating with Java EE
        5. Job Scheduling Support
        6. Mail Support
        7. Dynamic Languages
        8. Remoting Support
        9. Managing Transactions
        10. The Spring MVC Framework
        11. Spring Web Flow
        12. AJAX
        13. Internationalization
        14. Simplified Exception Handling
      2. The Spring Project
        1. Origins of Spring
        2. The Spring Community
        3. Spring for Microsoft .NET
        4. The Spring IDE
        5. The Spring Security (Formerly Acegi)
        6. Alternatives to Spring
      3. The Sample Code
      4. Summary
    2. 2. Getting Started
      1. Obtaining the Spring Framework
        1. Checking Out Spring from CVS
        2. Building Spring from Source Code
        3. Verifying Your Spring Distribution
        4. Spring Packaging
        5. Spring Dependencies
        6. Spring Sample Applications
        7. Setting Up Spring and Your IDE
      2. Hello, World
      3. Putting Spring Into "Hello, World"
        1. Dependency Injection
        2. The Impact of Spring
      4. Summary
    3. 3. Introducing Inversion of Control
      1. IoC and DI
      2. Types of IoC
        1. Contextualized Dependency Lookup
        2. Constructor DI
        3. Setter DI
        4. Injection vs. Lookup
        5. Setter Injection vs. Constructor Injection
      3. IoC in Spring
      4. DI with Spring
        1. Beans and BeanFactories
        2. BeanFactory Implementations
        3. XML Bean Definition
        4. Using Constructor Injection
        5. Injection Parameters
        6. Understanding Bean Naming
        7. Bean Instantiation Modes
        8. Resolving Dependencies
        9. Automatically Wiring Your Beans
        10. Checking Dependencies
        11. Bean Inheritance
      5. Summary
    4. 4. Beyond the Basics
      1. Spring's Impact on Application Portability
      2. Bean Life Cycle Management
        1. Hooking into Bean Creation
        2. Hooking into Bean Destruction
      3. Making Your Beans Spring Aware
        1. Using the BeanNameAware Interface
        2. Using the BeanFactoryAware Interface
      4. Using Method Injection
        1. Lookup Method Injection
        2. Method Replacement
      5. Using FactoryBean
        1. The MessageDigestFactoryBean
        2. Accessing a FactoryBean Directly
      6. The BeanFactoryPostProcessor
        1. Implementing a BeanFactoryPostProcessor
      7. JavaBeans PropertyEditor
        1. The Built-in PropertyEditors
        2. Creating a Custom PropertyEditor
      8. The BeanPostProcessor
        1. Implementing a BeanPostProcessor
        2. When to Use BeanPostProcessor
      9. The Spring ApplicationContext
        1. Implementations of ApplicationContext
        2. Using ApplicationContextAware
        3. Controlling Bean Initialization
        4. Using Annotation-Based Configuration
        5. Internationalization with MessageSource
        6. Using MessageSource in Stand-Alone Applications
        7. The MessageSourceResolvable Interface
        8. Using Application Events
        9. Considerations for Event Usage
        10. Accessing Resources
      10. Summary
    5. 5. Introducing Spring AOP
      1. AOP Concepts
      2. Types of AOP
        1. Static AOP
        2. Dynamic AOP
        3. Choosing an AOP Type
      3. AOP in Spring
        1. The AOP Alliance
        2. "Hello, World" in AOP
        3. Spring AOP Architecture
        4. The ProxyFactory Class
        5. Creating Advice in Spring
      4. Advisors and Pointcuts in Spring
        1. The Pointcut Interface
        2. Using ComposablePointcut
        3. Pointcutting Summary
      5. All About Proxies
        1. Understanding Proxies
        2. Using JDK Dynamic Proxies
        3. Using CGLIB Proxies
        4. Comparing Proxy Performance
        5. Which Proxy to Use?
      6. Summary
    6. 6. Advanced AOP
      1. @AspectJ
      2. @AspectJ Aspects in Detail
        1. Pointcuts
        2. Pointcut Expressions
        3. Exploring the Pointcut Expressions
        4. Using the @Pointcuts in XML
        5. Types of Advice
        6. Argument Binding
        7. Introductions
        8. The Aspect Life Cycle
      3. Framework Services for AOP
        1. Creating Our First Aspect Using the aop Namespace
        2. Pointcuts in the aop Namespace
        3. Creating Advice Using the aop Namespace
        4. Introductions in the aop Namespace
      4. Which Style Should You Use?
      5. Working with Spring AOP Proxies
        1. Impact of Proxies
      6. AspectJ Integration
        1. Creating Your First AspectJ Aspect
        2. Compiling the Sample Application
        3. AspectJ's Aspect Scope
      7. Load-Time Weaving
        1. Your First Load-Time Weaving Example
        2. LoadTimeWeaver Lookup Strategies
      8. Practical Uses of AOP
        1. Performance and Health Monitoring
      9. Summary
    7. 7. Spring Schemas and Namespaces
      1. Why the New Configuration?
      2. Schemas Included in Spring 2.5
        1. The beans Schema
        2. The context Schema
        3. The util Schema
        4. The tx Schema
        5. The aop Schema
        6. The jee Schema
        7. The lang Schema
      3. Behind the Schema Scenes
      4. Custom Schemas
      5. IDE Configuration
      6. Summary
    8. 8. Spring Patterns
      1. Directory Structure
        1. Simple Applications
        2. Complex Applications
        3. Packaging and Naming
      2. Design Patterns Introduction
        1. Programming Against Interfaces
        2. Creational Patterns
        3. Structural Patterns
        4. Behavioral Patterns
        5. Template Method
      3. Spring Application Patterns
        1. Layered Design
        2. High-Performance Paging
        3. Multiple Error Reporting
        4. User Interface Transactions
        5. Background Processes
        6. E-mail Notifications
        7. Error Collecting and Logging
      4. Summary
  8. II. Data Access
    1. 9. JDBC Support
      1. Key JDBC Concepts
        1. Using the DriverManager and Connections
        2. Using PreparedStatements
        3. Using CallableStatements
        4. Other JDBC Concepts
      2. Concepts in Spring Data Access Support
      3. JDBC Data Access Support
      4. Using the JdbcTemplate
        1. JdbcTemplate.execute
        2. JdbcTemplate.query and Friends
        3. JdbcTemplate.update
        4. JdbcTemplate.batchUpdate
      5. RdbmsOperation Subclasses
        1. SqlUpdate
        2. BatchSqlUpdate
        3. SqlCall and StoredProcedure
        4. SqlQuery and Its Subclasses
        5. JdbcTemplate or RdbmsOperation?
      6. Large Binary Objects
      7. JdbcDaoSupport
      8. Simple Spring JDBC
        1. SimpleJdbcTemplate
        2. SimpleJdbcCall
        3. SimpleJdbcInsert
        4. SimpleJdbcDaoSupport
      9. Summary
    2. 10. iBATIS Integration
      1. What Is iBATIS?
        1. iBATIS Versions
        2. Infrastructure and Configuration
      2. Mapping Files
        1. sqlMap Files
        2. Configuring iBATIS and Spring
      3. Selecting Data
        1. Simple Selects
        2. One-to-One Selects
        3. One-to-Many Selects
        4. Many-to-Many Selects
      4. Updating Data
      5. Deleting Data
      6. Inserting Data
      7. What's Missing from iBATIS?
      8. Overall Performance
      9. Summary
    3. 11. Hibernate Support
      1. Hibernate Primer
      2. Packaging
      3. Introduction to Hibernate Support
        1. Using Hibernate Sessions
        2. Using HibernateDaoSupport
        3. Deciding Between HibernateTemplate and Session
      4. Using Hibernate in Enterprise Applications
        1. Preventing Stale Data Updates
        2. Object Equality
        3. Transactional Behavior
        4. Lazy Loading
        5. Dealing with Large Data Sets
        6. Handling Large Objects
        7. Combining Hibernate with Other DAO Code
      5. Summary
  9. III. Enterprise Application Components
    1. 12. Job Scheduling with Spring
      1. Scheduling Jobs Using JDK Timer
        1. Trigger Types with Timer
        2. Creating a Simple Job
        3. Spring Support for JDK Timer Scheduling
      2. Scheduling Jobs Using OpenSymphony Quartz
        1. Introducing Quartz
        2. Quartz Support in Spring
      3. Job Scheduling Considerations
        1. Choosing a Scheduler
        2. Packaging Job Logic Separately from the Job Class
        3. Task Execution and Thread Pooling
      4. Summary
    2. 13. Mail Support in Spring
      1. The Spring Mail API Structure
        1. Configuring Mail Settings Using Spring
      2. Sending Simple E-mails
        1. Constructing and Sending E-mail Programmatically
        2. Constructing E-mail Declaratively
        3. Constructing and Sending MIME Messages
        4. Insight into Enterprise-Level E-mail Handling
      3. Summary
    3. 14. Dynamic Languages
      1. Supported Languages Primer
        1. BeanShell
        2. Groovy
        3. JRuby
      2. Using Dynamic Languages As Spring Beans
        1. Behind the Scenes of Dynamic Language Support
        2. Proxying Dynamic Language Beans
        3. Performance
      3. Refreshable Beans
      4. BeanShell Beans
      5. JRuby Beans
      6. Groovy Beans
      7. Typical Usage for Dynamic Languages in Spring Applications
      8. Summary
  10. IV. Java EE 5
    1. 15. Using Spring Remoting
      1. Spring Remoting Architecture
      2. Remote Method Invocation
        1. Exposing Arbitrary Services
        2. Accessing an RMI Service Using Proxies
        3. Exposing CORBA Services
        4. Accessing a CORBA Service
      3. Web Services with JAX-RPC
        1. Introducing Apache Axis
        2. Creating a Web Service with ServletEndpointSupport
        3. Accessing RPC-Style Web Services using Proxies
        4. Working with JavaBeans in Axis Services
      4. Using JAX-WS Web Services
        1. Exposing Web Services Using SimpleJaxWsServiceExporter
        2. Exposing a Web Service Using XFire
        3. Accessing JAX-WS Web Services
        4. Accessing Java Web Services from Other Clients
      5. Creating Web Services with HTTP Invoker
        1. Exposing Simple Services
        2. Accessing an HTTP Invoker Service Using Proxies
        3. Using Arbitrary Objects in HTTP Invoker Services
        4. Using HTTP Basic Authentication
      6. Choosing a Remoting Architecture
      7. Summary
    2. 16. Transaction Management
      1. Exploring the Spring Transaction Abstraction Layer
      2. Analyzing Transaction Properties
        1. Exploring the TransactionDefinition Interface
        2. Using the TransactionStatus Interface
        3. Implementations of the PlatformTransactionManager
      3. Exploring a Transaction Management Sample
        1. Nontransactional Code
      4. Programmatic Transaction Management
        1. Using the TransactionTemplate Class
        2. Programmatic Transaction Management Summary
      5. Declarative Transaction Management
        1. Using the TransactionProxyFactoryBean
        2. Implications of Using Proxies in Transaction Management
      6. AOP Transaction Management
        1. Using Annotation-Based AOP Transaction Management
        2. Using XML AOP Transaction Management
      7. Working with Transactions Over Multiple Transactional Resources
      8. Implementing Your Own Transaction Synchronization
      9. Summary
    3. 17. Web Applications with Spring MVC
      1. MVC Architecture
      2. Spring MVC
        1. MVC Implementation
      3. Using Handler Mappings
      4. Spring Controllers
        1. AbstractController
        2. ParameterizableViewController
        3. MultiActionController
      5. Interceptors
      6. Views, Locales, and Themes
        1. Using Views Programmatically
        2. Using View Resolvers
        3. Using Localized Messages
        4. Using Locales
        5. Using Themes
      7. Command Controllers
        1. Using Form Controllers
        2. Exploring the AbstractWizardFormController
        3. File Upload
      8. Handling Exceptions
      9. Spring and Other Web Technologies
        1. Using JSP
        2. Using Velocity
        3. FreeMarker
        4. Using XSLT Views
        5. Using PDF Views
        6. Using Excel Views
        7. Using Tiles
        8. JasperReports
      10. Spring Conventions Over Configuration
        1. Controller Conventions
        2. MultiActionController Conventions
        3. Model Conventions
        4. View Conventions
      11. Using Annotations for Controller Configuration
        1. @Controller
        2. @RequestMapping
        3. @RequestParam
        4. @ModelAttribute
        5. Using Annotations with the Command Controller
      12. Summary
    4. 18. Spring Web Flow
      1. Introducing Spring Web Flow
        1. Core Concepts
        2. Obtaining Spring Web Flow
        3. Spring Web Flow Dependencies
      2. Hello, Web Flow!
      3. Exploring States
        1. View State
        2. Decision State
        3. End State
      4. Working with Transitions
      5. Advanced Concepts
        1. Expression Languages and Scopes
        2. Implementing Actions
        3. Model Data Binding
        4. Partial Rendering of Views
        5. Mapping Flow Input and Output Parameters
        6. Using Subflows
      6. Spring Web Flow Behind the Scenes
        1. Flow Execution Architecture
        2. Flow Executor
        3. Flow Definition Registry
        4. Flow Execution Repository
      7. Integration with Spring MVC
        1. Flow Handling
        2. View Resolving
      8. Securing Flows with Spring Security
        1. Step 1: Adding the SecurityFlowExecutionListener
        2. Step 2: Basic Authentication and Authorization Handling
        3. Step 3: Defining Security Rules in Flow Definitions
      9. Problem Solver
        1. Stateful Navigational Control
        2. Browser Navigation Bar Support and Double Submit
      10. Testing Flow Definitions
      11. Summary
    5. 19. Spring and AJAX
      1. DWR
      2. Installing DWR
      3. Spring Configuration for DWR
      4. About the Complete Example
      5. Testing the DWR Configuration
      6. Running the Complete Example
      7. DWR Scripting Basics
        1. Using Simple Callback Functions
        2. Calling Metadata Objects
      8. engine.js
        1. Call Batching
        2. Call Ordering
        3. Handling Errors and Warnings
      9. util.js
      10. Security in DWR
      11. Advantages and Disadvantages of DWR
      12. Summary
    6. 20. JMX with Spring
      1. JMX Refresher
      2. Exposing Your Beans
        1. MBeanExporter
        2. MBeanServerFactoryBean
        3. Exposing Your Beans in an Existing MBean Server
        4. Bean Registration Behavior
      3. Controlling Object Names
      4. Controlling the Management Interface
        1. MBeanInfoAssembler Interface
        2. MethodNameBasedMBeanInfoAssembler Interface
        3. Using Java Interfaces to Control the Management Interface
        4. Using Source-Level Metadata
      5. Remoting with Spring JMX
        1. Exposing Remote MBeans
        2. Accessing Remote MBeans
        3. Proxying MBeans
      6. Notifications in Spring JMX
        1. Notification Listeners
        2. Publishing Notifications
      7. Summary
    7. 21. Testing with Spring
      1. Unit Testing
      2. Unit Tests
        1. Unit Testing the Web Layer
      3. Integration Tests
        1. Using AbstractSpringContextTests
        2. Using AbstractDependencyInjectionSpringContextTests
        3. Using AbstractTransactionalSpringContextTests
        4. Using AbstractAnnotationAwareTransactionalTests
        5. JNDI
      4. Spring TestContext Framework
        1. Application Context and DI with the TestContext Framework
        2. Transactions in the TestContext Framework
        3. Support Classes
      5. Test Coverage
      6. Summary
    8. 22. Spring Performance Tuning
      1. Performance vs. Responsiveness
      2. Exploring Enterprise Application Performance Issues
      3. Measuring Java EE Application Performance
        1. Finding Out What to Measure
        2. Determining the Necessary Data Sets
        3. Improving the Data Access Tier
        4. Improving Transaction Management
        5. Controlling the Performance of Remote Calls
        6. Understanding View Performance
      4. Using Caching
      5. Performance Testing
      6. Monitoring Application Health and Performance
      7. More Resources on Performance Tuning
      8. Summary