1. Trang chủ
  2. » Công Nghệ Thông Tin

Spring Recipes, 2nd Edition pdf

1.1K 7.2K 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Prelim

  • Contents at a Glance

  • Contents

  • About the Authors

  • About the Technical Reviewers

  • Acknowledgments

  • Introduction

    • Who This Book Is For

    • How This Book Is Structured

    • Conventions

    • Prerequisites

    • Downloading the code

    • Contacting the Authors

  • Introduction to Spring

    • 1-1. Instantiating the Spring IoC Container

      • Problem

      • Solution

      • How It Works Instantiating an Application Context

      • Getting Beans from the IoC Container

    • 1-2. Configuring Beans in the Spring IoC Container

      • Problem

      • Solution

      • How It Works

      • Creating the Bean Class

      • Creating the Bean Configuration File

      • Declaring Beans in the Bean Configuration File

      • Defining Bean Properties by Shortcut

      • Configuring Collections for Your Beans

      • Lists, Arrays, and Sets

      • Maps and Properties

    • 1-3. Creating Beans by Invoking a Constructor

      • Problem

      • Solution

      • How It Works

    • 1-4. Resolving Constructor Ambiguity

      • Problem

      • Solution

      • How It Works

    • 1-5. Specifying Bean References

      • Problem

      • Solution

      • How It Works

      • Specifying Bean References for Setter Methods

      • Specifying Bean References for Constructor Arguments

      • Declaring Inner Beans

    • 1-6. Specifying the Data Type for Collection Elements

      • Problem

      • Solution

      • How It Works

    • 1-7. Creating Beans Using Spring’s FactoryBean

      • Problem

      • Solution

      • How It Works

    • 1-8. Defining Collections Using Factory Beans and the Utility Schema

      • Problem

      • Solution

      • How It Works Specifying the Concrete Class for Collections

      • Defining Stand-Alone Collections

    • 1-9. Checking Properties with Dependency Checking

      • Problem

      • Solution

      • How It Works Checking Properties of the Simple Types

      • Checking Properties of the Object Types

      • Checking Properties of All Types

      • Dependency Checking and Constructor Injection

    • 1-10. Checking Properties with the @Required Annotation

      • Problem

      • Solution

      • How It Works

    • 1-11. Auto-Wiring Beans with XML Configuration

      • Problem

      • Solution

      • How It Works Auto-Wiring by Type

      • Auto-Wiring by Name

      • Auto-Wiring by Constructor

      • Auto-Wiring by Auto-Detection

      • Auto-Wiring and Dependency Checking

    • 1-12. Auto-Wiring Beans with @Autowired and @Resource

      • Problem

      • Solution

      • How It Works

      • Auto-Wiring a Single Bean of Compatible Type

      • Auto-Wiring All Beans of Compatible Type

      • Auto-Wiring by Type with Qualifiers

      • Auto-Wiring by Name

    • 1-13. Inheriting Bean Configuration

      • Problem

      • Solution

      • How It Works

    • 1-14. Scanning Components from the Classpath

      • Problem

      • Solution

      • How It Works

      • Scanning Components Automatically

      • Filtering Components to Scan

      • Naming Detected Components

    • Summary

  • Advanced Spring IoC Container

    • 2-1. Creating Beans by Invoking a Static Factory Method

      • Problem

      • Solution

      • How It Works

    • 2-2. Creating Beans by Invoking an Instance Factory Method

      • Problem

      • Solution

      • How It Works

    • 2-3. Declaring Beans from Static Fields

      • Problem

      • Solution

      • How It Works

    • 2-4. Declaring Beans from Object Properties

      • Problem

      • Solution

      • How It Works

    • 2-5. Using the Spring Expression Language

      • Problem

      • Solution

      • How It Works

      • Features of the Language Syntax

      • Uses of the Language in Your Configurations

      • Using the Spring Expression Language Parser

    • 2-6. Setting Bean Scopes

      • Problem

      • Solution

      • How It Works

    • 2-7. Customizing Bean Initialization and Destruction

      • Problem

      • Solution

      • How It Works

      • Implementing the InitializingBean and DisposableBean Interfaces

      • Setting the init-method and destroy-method Attributes

      • Annotating the @PostConstruct and @PreDestroy Annotations

    • 2-8. Reducing XML Configuration with Java Config

      • Problem

      • Solution

      • How It Works

    • 2-9. Making Beans Aware of the Container

      • Problem

      • Solution

      • How It Works

    • 2-10. Loading External Resources

      • Problem

      • Solution

      • How It Works

      • Resource Prefixes

      • Injecting Resources

    • 2-11. Creating Bean Post Processors

      • Problem

      • Solution

      • How It Works

    • 2-12. Externalizing Bean Configurations

      • Problem

      • Solution

      • How It Works

    • 2-13. Resolving Text Messages

      • Problem

      • Solution

      • How It Works

    • 2-14. Communicating with Application Events

      • Problem

      • Solution

      • How It Works Defining Events

      • Publishing Events

      • Listening to Events

    • 2-15. Registering Property Editors in Spring

      • Problem

      • Solution

      • How It Works

    • 2-16. Creating Custom Property Editors

      • Problem

      • Solution

      • How It Works

    • 2-17. Concurrency with TaskExecutors

      • Problem

      • Solution

      • How It Works

      • Java SE

      • Java EE

      • Spring’s Solution

    • Summary

  • Spring AOP and AspectJ Support

    • 3-1. Enabling AspectJ Annotation Support in Spring

      • Problem

      • Solution

      • How It Works

    • 3-2. Declaring Aspects with AspectJ Annotations

      • Problem

      • Solution

      • How It Works Before Advices

      • After Advices

      • After Returning Advices

      • After Throwing Advices

      • Around Advices

    • 3-3. Accessing the Join Point Information

      • Problem

      • Solution

      • How It Works

    • 3-4. Specifying Aspect Precedence

      • Problem

      • Solution

      • How It Works

    • 3-5. Reusing Pointcut Definitions

      • Problem

      • Solution

      • How It Works

    • 3-6. Writing AspectJ Pointcut Expressions

      • Problem

      • Solution

      • How It Works Method Signature Patterns

      • Type Signature Patterns

      • Bean Name Patterns

      • Combining Pointcut Expressions

      • Declaring Pointcut Parameters

    • 3-7. Introducing Behaviors to Your Beans

      • Problem

      • Solution

      • How It Works

    • 3-8. Introducing States to Your Beans

      • Problem

      • Solution

      • How It Works

    • 3-9. Declaring Aspects with XML-Based Configurations

      • Problem

      • Solution

      • How It Works

      • Declaring Aspects

      • Declaring Pointcuts

      • Declaring Advices

      • Declaring Introductions

    • 3-10. Load-Time Weaving AspectJ Aspects in Spring

      • Problem

      • Solution

      • How It Works

      • Load-Time Weaving by the AspectJ Weaver

      • Load-Time Weaving by Spring Load-Time Weaver

    • 3-11. Configuring AspectJ Aspects in Spring

      • Problem

      • Solution

      • How It Works

    • 3-12. Injecting Spring Beans into Domain Objects

      • Problem

      • Solution

      • How It Works

    • Summary

  • Scripting in Spring

    • 19-1. Implementing Beans with Scripting Languages

      • Problem

      • Solution

      • How It Works

      • Scripting Beans with JRuby

      • Scripting Beans with Groovy

      • Scripting Beans with BeanShell

    • 19-2. Injecting Spring Beans into Scripts

      • Problem

      • Solution

      • How It Works

      • Injecting Spring Beans into JRuby

      • Injecting Spring Beans into Groovy

      • Injecting Spring Beans into BeanShell

    • 19-3. Refreshing Beans from Scripts

      • Problem

      • Solution

      • How It Works

    • 19-4. Defining Script Sources Inline

      • Problem

      • Solution

      • How It Works

    • Summary

  • Spring Security

    • 5-1. Securing URL Access

      • Problem

      • Solution

      • How It Works

      • Setting Up a Spring MVC Application That Uses Spring Security

      • Creating the Configuration Files

      • Creating the Controllers and Page Views

      • Securing URL Access

    • 5-2. Logging In to Web Applications

      • Problem

      • Solution

      • How It Works

      • HTTP Basic Authentication

      • Form-Based Login

      • The Logout Service

      • Anonymous Login

      • Remember-Me Support

    • 5-3. Authenticating Users

      • Problem

      • Solution

      • How It Works Authenticating Users with In-Memory Definitions

      • Authenticating Users Against a Database

      • Encrypting Passwords

      • Authenticating Users Against an LDAP Repository

      • Caching User Details

    • 5-4. Making Access Control Decisions

      • Problem

      • Solution

      • How It Works

    • 5-5. Securing Method Invocations

      • Problem

      • Solution

      • How It Works Securing Methods by Embedding a Security Interceptor

      • Securing Methods with Pointcuts

      • Securing Methods with Annotations

    • 5-6. Handling Security in Views

      • Problem

      • Solution

      • How It Works Displaying Authentication Information

      • Rendering View Contents Conditionally

    • 5-7. Handling Domain Object Security

      • Problem

      • Solution

      • How It Works Setting Up an ACL Service

      • Maintaining ACLs for Domain Objects

      • Making Access Control Decisions Based on ACLs

      • Handling Domain Objects Returned from Methods

    • Summary

  • Integrating Spring with Other Web Frameworks

    • 6-1. Accessing Spring in Generic Web Applications

      • Problem

      • Solution

      • How It Works

    • 6-2. Using Spring in Your Servlets and Filters

      • Problem

      • Solution

      • How It Works

    • 6-3. Integrating Spring with Struts 1.x

      • Problem

      • Solution

      • How It Works

      • Loading Spring’s Application Context into a Struts Application

      • Accessing Spring’s Application Context in Struts Actions

      • Declaring Struts Actions in Spring’s Bean Configuration File

    • 6-4. Integrating Spring with JSF

      • Problem

      • Solution

      • How It Works

      • Resolving Spring Beans in JSF

      • Declaring JSF Managed Beans in Spring’s Bean Configuration File

    • 6-5. Integrating Spring with DWR

      • Problem

      • Solution

      • How It Works

      • Exposing Spring Beans for Remote Invocation

      • Configuring DWR in Spring’s Bean Configuration File

    • Summary

  • Spring Web Flow

    • 7-1. Managing a Simple UI Flow with Spring Web Flow

      • Problem

      • Solution

      • How It Works

      • Setting Up a Spring MVC Application That Uses Spring Web Flow

      • Creating the Configuration Files

      • Creating Web Flow Definitions

      • Creating the Page Views

    • 7-2. Modeling Web Flows with Different State Types

      • Problem

      • Solution

      • How It Works

      • Defining View States

      • Defining Action States

      • Defining Decision States

      • Defining End States

      • Defining Subflow States

    • 7-3. Securing Web Flows

      • Problem

      • Solution

      • How It Works

    • 7-4. Persisting Objects in Web Flows

      • Problem

      • Solution

      • How It Works

      • Configuring JPA in Spring’s Application Context

      • Setting Up JPA for Spring Web Flow

      • Using JPA in Web Flows

    • 7-5. Integrating Spring Web Flow with JSF

      • Problem

      • Solution

      • How It Works Rendering JSF Views for Spring Web Flow

      • Actions and ActionListeners

      • Using the JSF Components of Spring Faces

    • 7-6. Using RichFaces with Spring Web Flow

      • Problem

      • Solution

      • Approach

      • Setting Up RichFaces With JSF

    • Summary

  • Spring @MVC

    • 8-1. Developing a Simple Web Application with Spring MVC

      • Problem

      • Solution

      • How It Works

      • Setting up a Spring MVC Application

      • Creating the Configuration Files

      • Activating Spring MVC annotation scanning

      • Creating Spring MVC Controllers

      • Creating JSP Views

      • Deploying the Web Application

    • 8-2. Mapping requests with @RequestMapping

      • Problem

      • Solution

      • How It Works Mapping requests by method

      • Mapping requests by class

      • Mapping requests by HTTP request type

    • 8-3. Intercepting Requests with Handler Interceptors

      • Problem

      • Solution

      • How It Works

    • 8-4. Resolving User Locales

      • Problem

      • Solution

      • How It Works Resolving Locales by an HTTP Request Header

      • Resolving Locales by a Session Attribute

      • Resolving Locales by a Cookie

      • Changing a User’s Locale

    • 8-5. Externalizing Locale-Sensitive Text Messages

      • Problem

      • Solution

      • How It Works

    • 8-6. Resolving Views by Names

      • Problem

      • Solution

      • How It Works Resolving Views Based on a template’s name and location

      • Resolving Views from an XML Configuration File

      • Resolving Views from a Resource Bundle

      • Resolving Views with Multiple Resolvers

      • The Redirect Prefix

    • 8-7. Views and Content Negotiation

      • Problem

      • Solution

      • How It Works

    • 8-8. Mapping Exceptions to Views

      • Problem

      • Solution

      • How It Works

    • 8-9. Assigning values in a Controller with @Value

      • Problem

      • Solution

      • How It Works

    • 8-10. Handling Forms with Controllers

      • Problem

      • Solution

      • How It Works

      • Creating a form’s views

      • Creating a form’s service processing

      • Creating a form’s controller

      • Initializing a model attribute object and pre-populating a form with values

      • Providing form Reference Data

      • Binding Properties of Custom Types

      • Validating Form Data

      • Expiring a controller’s Session Data

    • 8-11. Handling Multipage Forms with Wizard Form Controllers

      • Problem

      • Solution

      • How It Works

      • Creating Wizard Form Pages

      • Creating a Wizard Form Controller

      • Validating Wizard Form Data

    • 8-12. Bean validation with Annotations (JSR-303)

      • Problem

      • Solution

      • How It Works

    • 8-13. Creating Excel and PDF Views

      • Problem

      • Solution

      • How It Works

      • Creating Excel Views

      • Creating PDF Views

      • Creating resolvers for Excel and PDF views

      • Creating date based PDF and XLS file names

    • Summary

  • Spring REST

    • 9-1. Publishing a REST Service with Spring

      • Problem

      • Solution

      • How It Works

    • 9-2. Accessing a REST Service with Spring

      • Problem

      • Solution

      • How It Works

    • 9-3. Publishing RSS and Atom feeds

      • Problem

      • Solution

      • How It Works

    • 9-4. Publishing JSON with REST services

      • Problem

      • Solution

      • How It Works

    • 9-5. Accessing REST Services with Elaborate XML Responses

      • Problem

      • Solution

      • How It Works

    • Summary

  • Spring and Flex

    • 10-1. Getting started with Flex

      • Problem

      • Solution

      • How It Works

      • Flex Development Basics

      • The Tools

    • 10-2. Leaving the Sandbox

      • Problem

      • Solution

      • How It Works

      • FlashVars

      • ExternalInterface

      • HTTP and HTTPS

      • Consuming SOAP Services

      • Flash Remoting with AMF

    • 10-3. Adding the Spring BlazeDS support to an application

      • Problem

      • Solution

      • How It Works

      • Installing the Spring Support

    • 10-4. Exposing Services Through BlazeDS / Spring

      • Problem

      • Solution

      • How It Works

    • 10-5. Working With Server-Side Objects

      • Problem

      • Solution

      • How It Works

    • 10-6. Consuming Message-Oriented Services Using BlazeDS and Spring

      • Problem

      • Solution

      • How It Works

      • JMS

      • Spring Integration

      • BlazeDS

      • Sending Messages from Flex

    • 10-7. Bringing Dependency Injection to your ActionScript Client

      • Problem

      • Solution

      • How It Works

    • Summary

  • Grails

    • 11-1. Getting and Installing Grails

      • Problem

      • Solution

      • How It Works

    • 11-2. Creating a Grails Application

      • Problem

      • Solution

      • How It Works

      • A Grails Application’s File and Directory Structure

      • Running an Application

      • Creating Your First Grails Application Construct

      • Exporting a Grails Application to a WAR

    • 11-3. Grails Plug-Ins

      • Problem

      • Solution

      • How It Works

    • 11-4. Developing, Producing, and Testing in Grails Environments

      • Problem

      • Solution

      • How It Works

    • 11-5. Creating an Application’s Domain Classes

      • Problem

      • Solution

      • How It Works

    • 11-6. Generating CRUD Controllers and Views for an Application’s Domain Classes

      • Problem

      • Solution

      • How It Works

    • 11-7. Internationalization (I18n) Message Properties

      • Problem

      • Solution

      • How it works

    • 11-8. Changing Permanent Storage Systems

      • Problem

      • Solution

      • How It Works

      • Setting Up an RDBMS Driver

      • Configuring an RDBMS Instance

    • 11-9. Logging

      • Problem

      • Solution

      • How It Works

      • Configuring Custom Appenders and Loggers

      • Configuring Layouts

    • 11-10. Running Unit and Integration Tests

      • Problem

      • Solution

      • How It Works

    • 11-11. Using Custom Layouts and Templates

      • Problem

      • Solution

      • How It Works

    • 11-12. Using GORM Queries

      • Problem

      • Solution

      • How It Works

    • 11-13. Creating Custom Tags

      • Problem

      • Solution

      • How It Works

    • Summary

  • Spring Roo

    • 12-1. Setting Up the Spring Roo Development Environment

      • Problem

      • Solution

      • How It Works

      • Maven

      • SpringSource Tool Suite

      • Spring Roo

    • 12-2. Creating Your First Spring Roo Project

      • Problem

      • Solution

      • How It Works

      • Exploring the Maven Project

      • Getting Started Using STS

    • 12-3. Importing an Existing Project into SpringSource Tool Suite

      • Problem

      • Solution

      • How It Works

    • 12-4. Building A Better Application, Quicker

      • Problem

      • Solution

      • How It Works

      • Coding the Backend

      • Coding the Front-end

    • 12-5. Removing Spring Roo from Your Project

      • Problem

      • Solution

      • How It Works

    • Summary

  • Spring Testing

    • 13-1. Creating Tests with JUnit and TestNG

      • Problem

      • Solution

      • How It Works

      • Testing with JUnit 3

      • Testing with JUnit 4

      • Testing with TestNG

    • 13-2. Creating Unit Tests and Integration Tests

      • Problem

      • Solution

      • How It Works Creating Unit Tests for Isolated Classes

      • Creating Unit Tests for Dependent Classes Using Stubs and Mock Objects

      • Creating Integration Tests

    • 13-3. Unit Testing Spring MVC Controllers

      • Problem

      • Solution

      • How It Works

    • 13-4. Managing Application Contexts in Integration Tests

      • Problem

      • Solution

      • How It Works

      • Accessing the Context with JUnit 3 Legacy Support

      • Accessing the Context with the TestContext Framework in JUnit 4

      • Accessing the Context with the TestContext Framework in JUnit 3

      • Accessing the Context with the TestContext Framework in TestNG

    • 13-5. Injecting Test Fixtures into Integration Tests

      • Problem

      • Solution

      • How It Works Injecting Test Fixtures with JUnit 3 Legacy Support

      • Injecting Test Fixtures with the TestContext Framework in JUnit 4

      • Injecting Test Fixtures with the TestContext Framework in JUnit 3

      • Injecting Test Fixtures with the TestContext Framework in TestNG

    • 13-6. Managing Transactions in Integration Tests

      • Problem

      • Solution

      • How It Works

      • Managing Transactions with JUnit 3 Legacy Support

      • Managing Transactions with the TestContext Framework in JUnit 4

      • Managing Transactions with the TestContext Framework in JUnit 3

      • Managing Transactions with the TestContext Framework in TestNG

    • 13-7. Accessing a Database in Integration Tests

      • Problem

      • Solution

      • How It Works Accessing a Database with JUnit 3 Legacy Support

      • Accessing a Database with the TestContext Framework

    • 13-8. Using Spring’s Common Testing Annotations

      • Problem

      • Solution

      • How It Works Using Common Testing Annotations with JUnit 3 Legacy Support

      • Using Common Testing Annotations with the TestContext Framework

    • Summary

  • Spring Portlet MVC Framework

    • 14-1. Developing a Simple Portlet with Spring Portlet MVC

      • Problem

      • Solution

      • How It Works

      • Setting Up a Portlet Application

      • Creating the Configuration Files

      • Creating Portlet Controllers

      • Resolving View Names into Views

      • Creating Portlet Views

      • Deploying the Portlet Application

    • 14-2. Mapping Portlet Requests to Handlers

      • Problem

      • Solution

      • How It Works

      • Mapping Requests by the Portlet Mode

      • Mapping Requests by a Parameter

    • 14-3. Handling Portlet Forms with Simple Form Controllers

      • Problem

      • Solution

      • How It Works

      • Creating Form Controllers

      • Validating Form Data

    • Summary

  • Data Access

    • Problems with Direct JDBC

      • Setting Up the Application Database

      • Understanding the Data Access Object Design Pattern

      • Implementing the DAO with JDBC

      • Configuring a Data Source in Spring

      • How It Works

      • Running the DAO

      • Taking It A Step Further

    • 15-1. Using a JDBC Template to Update a Database

      • Problem

      • Solution

      • How It Works Updating a Database with a Statement Creator

      • Updating a Database with a Statement Setter

      • Updating a Database with a SQL Statement and Parameter Values

      • Batch Updating a Database

    • 15-2. Using a JDBC Template to Query a Database

      • Problem

      • Solution

      • How It Works Extracting Data with Row Callback Handler

      • Extracting Data with a Row Mapper

      • Querying for Multiple Rows

      • Querying for a Single Value

    • 15-3. Simplifying JDBC Template Creation

      • Problem

      • Solution

      • How It Works Injecting a JDBC Template

      • Extending the JdbcDaoSupport Class

    • 15-4. Using the Simple JDBC Template with Java 1.5

      • Problem

      • Solution

      • How It Works Using a Simple JDBC Template to Update a Database

      • Using a Simple JDBC Template to Query a Database

    • 15-5. Using Named Parameters in a JDBC Template

      • Problem

      • Solution

      • How It Works

    • 15-6. Handling Exceptions in the Spring JDBC Framework

      • Problem

      • Solution

      • How It Works Understanding Exception Handling in the Spring JDBC Framework

      • Customizing Data Access Exception Handling

    • 15-7. Problems with Using ORM Frameworks Directly

      • Problem

      • Solution

      • How It Works

      • Persisting Objects Using the Hibernate API with Hibernate XML Mappings

      • Persisting Objects Using the Hibernate API with JPA Annotations

      • Persisting Objects Using JPA with Hibernate as the Engine

    • 15-8. Configuring ORM Resource Factories in Spring

      • Problem

      • Solution

      • How It Works Configuring a Hibernate Session Factory in Spring

      • Configuring a JPA Entity Manager Factory in Spring

    • 15-9. Persisting Objects with Spring’s ORM Templates

      • Problem

      • Solution

      • How It Works Using a Hibernate Template and a JPA Template

      • Extending the Hibernate and JPA DAO Support Classes

    • 15-10. Persisting Objects with Hibernate’s Contextual Sessions

      • Problem

      • Solution

      • How It Works

    • 15-11. Persisting Objects with JPA’s Context Injection

      • Problem

      • Solution

      • How It Works

    • Summary

  • Transaction Management in Spring

    • 16-1. Problems with Transaction Management

      • Managing Transactions with JDBC Commit and Rollback

    • 16-2. Choosing a Transaction Manager Implementation

      • Problem

      • Solution

      • How It Works

    • 16-3. Managing Transactions Programmatically with the Transaction Manager API

      • Problem

      • Solution

      • How It Works

    • 16-4. Managing Transactions Programmatically with a Transaction Template

      • Problem

      • Solution

      • How It Works

    • 16-5. Managing Transactions Declaratively with Transaction Advices

      • Problem

      • Solution

      • How It Works

    • 16-6. Managing Transactions Declaratively with the @Transactional Annotation

      • Problem

      • Solution

      • How It Works

    • 16-7. Setting the Propagation Transaction Attribute

      • Problem

      • Solution

      • How It Works

      • The REQUIRED Propagation Behavior

      • The REQUIRES_NEW Propagation Behavior

      • Setting the Propagation Attribute in Transaction Advices, Proxies, and APIs

    • 16-8. Setting the Isolation Transaction Attribute

      • Problem

      • Solution

      • How It Works

      • The READ_UNCOMMITTED and READ_COMMITTED Isolation Levels

      • The REPEATABLE_READ Isolation Level

      • The SERIALIZABLE Isolation Level

      • Setting the Isolation Level Attribute in Transaction Advices, Proxies, and APIs

    • 16-9. Setting the Rollback Transaction Attribute

      • Problem

      • Solution

      • How It Works

    • 16-10. Setting the Timeout and Read-Only Transaction Attributes

      • Problem

      • Solution

      • How It Works

    • 16-11. Managing Transactions with Load-Time Weaving

      • Problem

      • Solution

      • How It Works

    • Summary

  • EJB, Spring Remoting, and Web Services

    • 17-1. Exposing and Invoking Services Through RMI

      • Problem

      • Solution

      • How It Works

      • Exposing an RMI Service

      • Invoking an RMI Service

    • 17-2. Creating EJB 2.x Components with Spring

      • Problem

      • Solution

      • How It Works

      • Creating EJB 2.x Components Without Spring’s Support

      • Creating EJB 2.x Components with Spring’s Support

    • 17-3. Accessing Legacy EJB 2.x Components in Spring

      • Problem

      • Solution

      • How It Works

      • Accessing EJB 2.x Components

    • 17-4. Creating EJB 3.0 Components in Spring

      • Problem

      • Solution

      • How It Works

    • 17-5. Accessing EJB 3.0 Components in Spring

      • Problem

      • Solution

      • How It Works

      • Accessing EJB 3.0 Components with Spring’s Support

    • 17-6. Exposing and Invoking Services Through HTTP

      • Problem

      • Solution

      • How It Works Exposing a Hessian Service

      • Invoking a Hessian Service

      • Exposing a Burlap Service

      • Invoking a Burlap Service

      • Exposing an HTTP Invoker Service

      • Invoking an HTTP Invoker Service

    • 17-7. Choosing a SOAP Web Service Development Approach

      • Problem

      • Solution

      • How It Works Contract-Last Web Services

      • Contract-First Web Services

      • Comparison

    • 17-8. Exposing and Invoking a Contract-Last SOAP Web Services Using JAX-WS

      • Problem

      • Solution

      • How It Works

      • Exposing a Web Service Using The JAX-WS Endpoint Support in the JDK

      • Exposing a Web Service Using CXF

      • Invoking a Web Service Using CXF

    • 17-9. Defining the Contract of a Web Service

      • Problem

      • Solution

      • How It Works Creating Sample XML Messages

      • Generating an XSD File from Sample XML Messages

      • Optimizing the Generated XSD File

      • Previewing the Generated WSDL File

    • 17-10. Implementing Web Services Using Spring-WS

      • Problem

      • Solution

      • How It Works Setting Up a Spring-WS Application

      • Mapping Web Service Requests to Endpoints

      • Creating Service Endpoints

      • Publishing the WSDL File

    • 17-11. Invoking Web Services Using Spring-WS

      • Problem

      • Solution

      • How It Works

    • 17-12. Developing Web Services with XML Marshalling

      • Problem

      • Solution

      • How It Works Creating Service Endpoints with XML Marshalling

      • Invoking Web Services with XML Marshalling

    • 17-13. Creating Service Endpoints with Annotations

      • Problem

      • Solution

      • How It Works

    • Summary

  • Spring in the Enterprise

    • 18-1. Exporting Spring Beans as JMX MBeans

      • Problem

      • Solution

      • How It Works

      • Registering MBeans Without Spring’s Support

      • Exporting Spring Beans as MBeans

      • Exposing MBeans for Remote Access

      • Assembling the Management Interface of MBeans

      • Auto-Detecting MBeans by Annotations

    • 18-2. Publishing and Listening to JMX Notifications

      • Problem

      • Solution

      • How It Works Publishing JMX Notifications

      • Listening to JMX Notifications

    • 18-3. Accessing Remote JMX MBeans in Spring

      • Problem

      • Solution

      • How It Works Accessing Remote MBeans Through an MBean Server Connection

      • Accessing Remote MBeans Through an MBean Proxy

    • 18-4. Sending E-mail with Spring’s E-mail Support

      • Problem

      • Solution

      • How It Works

      • Sending E-mail Using the JavaMail API

      • Sending E-mail with Spring’s MailSender

      • Defining an E-mail Template

      • Sending MIME Messages

    • 18-5. Scheduling with Spring’s Quartz Support

      • Problem

      • Solution

      • How It Works Using Quartz Without Spring’s Support

      • Using Quartz with Spring’s Support

    • 18-6. Scheduling With Spring 3.0’s Scheduling Namespace

      • Problem

      • Solution

      • How It Works

    • Summary

  • Messaging

    • 19-1. Sending and Receiving JMS Messages with Spring

      • Problem

      • Solution

      • How It Works

      • Sending and Receiving Messages Without Spring’s Support

      • Sending and Receiving Messages with Spring’s JMS Template

      • Sending and Receiving Messages to and from a Default Destination

      • Extending the JmsGatewaySupport Class

    • 19-2. Converting JMS Messages

      • Problem

      • Solution

      • Approach

    • 19-3. Managing JMS Transactions

      • Problem

      • Approach

      • Solution

    • 19-4. Creating Message-Driven POJOs in Spring

      • Problem

      • Solution

      • How It Works

      • Listening for JMS Messages with Message Listeners

      • Listening for JMS Messages with POJOs

      • Converting JMS Messages

      • Managing JMS Transactions

      • Using Spring’s JMS Schema

    • 19-5. Making the Connection

      • Problem

      • Solution

      • How It Works

    • Summary

  • Spring Integration

    • 20-1. Integrating One System with Another Using EAI

      • Problem

      • Solution

      • How It Works Picking an Integration Style

      • Building on an ESB Solution

    • 20-2. Integrating Two Systems Using JMS

      • Problem

      • Solution

      • How it Works Building an Message Driven Pojo (MDP) Using Spring Integration

    • 20-3. Interrogating Spring Integration Messages for Context Information

      • Problem

      • Solution

      • How it Works Using MessageHeaders for Fun and Profit

    • 20-4. Integrating Two Systems Using a File System

      • Problem

      • Solution

      • How It Works Concerns in Dealing with a File System

    • 20-5. Transforming a Message from One Type to Another

      • Problem

      • Solution

      • How It Works

      • Modifying a Message’s Payload

      • Modifying a Message’s Headers

    • 20-6. Error Handling Using Spring Integration

      • Problem

      • Solution

      • How It Works

      • Routing to Custom Handlers Based on the Type of Exception

      • Building a Solution with Multiple Error Channels

    • 20-7. Forking Integration Control: Splitters and Aggregators

      • Problem

      • Solution

      • How it Works

      • Using a Splitter

      • Using Aggregators

    • 20-8. Conditional Routing with Routers

      • Problem

      • Solution

      • How It Works

    • 20-9. Adapting External Systems to the Bus

      • Problem

      • Solution

      • How It Works

      • An Inbound Twitter Adapter

      • Twitter Messages

      • A Simple MessageSource

      • An Outbound Twitter Example

    • 20-10. Staging Events Using Spring Batch

      • Problem

      • Solution

      • How It Works

    • 20-11. Using Gateways

      • Problem

      • Solution

      • How It Works

      • SimpleMessagingGateway

      • Breaking the Interface Dependency

    • Summary

  • Spring Batch

    • Runtime Metadata Model

    • 21-1. Setting Up Spring Batch’s Infrastructure

      • Problem

      • Solution

      • How It Works

    • 21-2. Reading and Writing (but No Arithmetic)

      • Problem

      • Solution

      • How It Works

      • The Job Configuration

      • Input

      • Output

    • 21-3. Writing a Custom ItemWriter and ItemReader

      • Problem

      • Solution

      • How It Works

      • Writing a Custom ItemReader

      • Writing a Custom ItemWriter

    • 21-4. Processing Input Before Writing

      • Problem

      • Solution

      • How It Works

      • Chaining Processors Together

    • 21-5. Better Living through Transactions

      • Problem

      • Solution

      • How It Works Transactions

      • Rollbacks

    • 21-6. Retrying

      • Problem

      • Solution

      • How It Works

      • Configuring a Step

      • Retry Template

      • AOP-Based Retries

    • 21-7. Controlling Step Execution

      • Problem

      • Solution

      • How It Works

      • Sequential Steps

      • Concurrency

      • Conditional Steps with Statuses

      • Conditional Steps with Decisions

    • 21-8. Launching a Job

      • Problem

      • Solution

      • How It Works

      • Launching From a Web Application

      • Running from the Command Line

      • Running On A Schedule

    • 21-9. Parameterizing a Job

      • Problem

      • Solution

      • How It Works Launching a Job with Parameters

      • Accessing JobParameters

    • Summary

  • Spring on the Grid

    • 22-1. Clustering Object State Using Terracotta

      • Problem

      • Solution

      • How It Works

      • Deploying a Simple Example with Terracotta

      • Terracotta Architecture and Deployment

      • The XML Configuration File

    • 22-2. Farming Out Execution to a Grid

      • Problem

      • Solution

      • Approach

      • Deployment

    • 22-3. Load Balancing a Method

      • Problem

      • Solution

      • Approach

    • 22-4. Parallelizing Processing

      • Problem

      • Solution

      • Approach

    • 22-5. Deploying on GridGain

      • Problem

      • Solution

      • How It Works

      • Creating a Grid Node

      • Provisioning a Grid Node

      • Getting Access to the Spring Container from a Task

      • Node-Specific GridGain Configuration

    • Summary

  • jBPM and Spring

    • Software Processes

    • 23-1. Understanding Workflow Models

      • Problem

      • Solution

      • How It Works

    • 23-2. Installing jBPM

      • Problem

      • Solution

      • How It Works

    • 23-3. Integrating jBPM 4 with Spring

      • Problem

      • Solution

      • How It Works

      • The Application Context

    • 23-4. Building a Service with Spring

      • Problem

      • Solution

      • How It Works

    • 23-5. Building a Business Process

      • Problem

      • Solution

      • How It Works

    • Summary

  • OSGi and Spring

    • 24-1. Getting Started with OSGi

      • Problem

      • Solution

      • How It Works

      • OSGi and JavaBeans

      • The helloworld-service Service

      • Installing Equinox

      • Using the Service in a Client Bundle

    • 24-2. Getting Started Using Spring Dynamic Modules

      • Problem

      • Solution

      • How It Works

    • 24-3. Exporting a Service Using Spring Dynamic Modules

      • Problem

      • Solution

      • How It Works

      • Interfacing with the OSGi Runtime

    • 24-4. Finding a Specific Service in the OSGi Registry

      • Problem

      • Solution

      • How It Works

      • Ranking

      • Service Attributes

      • Cardinality

    • 24-5. Publishing a Service Under Multiple Interfaces

      • Problem

      • Solution

      • How It Works

    • 24-6. Customizing Spring Dynamic Modules

      • Problem

      • Solution

      • How It Works

      • Making Spring Process OSGi Annotations on Beans

      • Changing the Default HTTP Server That Spring Uses When Deploying a .war

    • 24-7. Using SpringSource dm Server

      • Problem

      • Solution

      • How It Works

    • 24-8. SpringSource’s Tooling

      • Problem

      • Solution

      • How it Works

    • Summary

  • Index

    • ¦Characters and Numbers

    • A

    • ¦

    • ¦B

    • ¦C

    • ¦D

    • ¦E

    • ¦F

    • G

    • ¦

    • ¦H

    • ¦I

    • ¦J

    • ¦L

    • ¦K

    • M

    • ¦

    • N

    • ¦

    • ¦O

    • P

    • ¦

    • Q

    • ¦

    • ¦R

    • ¦S

    • ¦T

    • ¦U

    • ¦V

    • ¦W

    • ¦X

    • Y

    • ¦

    • ¦Z

Nội dung

THE EXPERT’S VOICE ® IN OPEN SOURCE Gary Mak, Josh Long, and Daniel Rubio Covers Spring Framework 3 Learn to use the full power of Spring 3 through coding recipes! SECOND EDITION Spring Recipes A Problem-Solution Approach www.it-ebooks.info www.it-ebooks.info Spring Recipes Second Edition ■ ■ ■ Gary Mak Josh Long Daniel Rubio www.it-ebooks.info Spring Recipes, Second Edition Copyright © 2010 by Gary Mak, Josh Long, and Daniel Rubio All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2499-0 ISBN-13 (electronic): 978-1-4302-2500-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Tom Welsh Technical Reviewer: Manuel Jordan, Mario Gray and Greg Turnquist Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Laurin Becker Copy Editor: Mary Ann Fugate, Heather Lang Production Support: Patrick Cunningham Indexer: BIM Indexing & Proofreading Services Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. For information on translations, please e-mail rights@apress.com, or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. www.it-ebooks.info To my parents, Clark Long and Kathleen MacDonald –Josh Long To my family –Daniel Rubio www.it-ebooks.info iv Contents at a Glance About the Author xxxvii About the Technical Reviewers xxxviii Acknowledgments xxxix Introduction xli ■Chapter 1: Introduction to Spring 1 ■Chapter 2: Advanced Spring IoC Container 61 ■Chapter 3: Spring AOP and AspectJ Support 117 ■Chapter 4: Scripting in Spring 159 ■Chapter 5: Spring Security 171 ■Chapter 6: Integrating Spring with Other Web Frameworks 219 ■Chapter 7: Spring Web Flow 249 ■Chapter 8: Spring @MVC 297 ■Chapter 9: Spring REST 371 ■Chapter 10: Spring and Flex 405 ■Chapter 11: Grails 459 ■Chapter 12: Spring Roo 501 ■Chapter 13: Spring Testing 525 ■Chapter 14: Spring Portlet MVC Framework 569 ■Chapter 15: Data Access 597 www.it-ebooks.info ■ CONTENTS AT A GLANCE v ■Chapter 16: Transaction Management in Spring 663 ■Chapter 17: EJB, Spring Remoting, and Web Services 707 ■Chapter 18: Spring in the Enterprise 765 ■Chapter 19: Messaging 803 ■Chapter 20: Spring Integration 829 ■Chapter 21: Spring Batch 875 ■Chapter 22: Spring on the Grid 909 ■Chapter 23: jBPM and Spring 935 ■Chapter 24: OSGi and Spring 959 Index 985 www.it-ebooks.info vi Contents About the Authors xxxvii About the Technical Reviewers xxxviii Acknowledgments xxxix Introduction xli ■Chapter 1: Introduction to Spring 1 1-1. Instantiating the Spring IoC Container 1 Problem 1 Solution 1 How It Works 3 1-2. Configuring Beans in the Spring IoC Container 4 Problem 4 Solution 4 How It Works 5 1-3. Creating Beans by Invoking a Constructor 14 Problem 14 Solution 15 How It Works 15 1-4. Resolving Constructor Ambiguity 18 Problem 18 Solution 18 How It Works 18 www.it-ebooks.info ■ CONTENTS vii 1-5. Specifying Bean References 21 Problem 21 Solution 21 How It Works 21 1-6. Specifying the Data Type for Collection Elements 25 Problem 25 Solution 25 How It Works 25 1-7. Creating Beans Using Spring’s FactoryBean 28 Problem 28 Solution 28 How It Works 28 1-8. Defining Collections Using Factory Beans and the Utility Schema 30 Problem 30 Solution 30 How It Works 30 1-9. Checking Properties with Dependency Checking 32 Problem 32 Solution 32 How It Works 33 1-10. Checking Properties with the @Required Annotation 35 Problem 35 Solution 35 How It Works 35 1-11. Auto-Wiring Beans with XML Configuration 38 Problem 38 Solution 38 How It Works 39 www.it-ebooks.info ■ CONTENTS viii 1-12. Auto-Wiring Beans with @Autowired and @Resource 42 Problem 42 Solution 42 How It Works 43 1-13. Inheriting Bean Configuration 49 Problem 49 Solution 49 How It Works 50 1-14. Scanning Components from the Classpath 53 Problem 53 Solution 53 How It Works 53 Summary 58 ■Chapter 2: Advanced Spring IoC Container 61 2-1. Creating Beans by Invoking a Static Factory Method 61 Problem 61 Solution 61 How It Works 61 2-2. Creating Beans by Invoking an Instance Factory Method 62 Problem 62 Solution 63 How It Works 63 2-3. Declaring Beans from Static Fields 64 Problem 64 Solution 64 How It Works 64 2-4. Declaring Beans from Object Properties 66 Problem 66 Solution 66 How It Works 66 www.it-ebooks.info [...]... ■Chapter 6: Integrating Spring with Other Web Frameworks 219 6-1 Accessing Spring in Generic Web Applications 220 Problem 220 Solution 220 How It Works 220 6-2 Using Spring in Your Servlets and Filters 224 Problem 224 Solution 225 How It Works 225 6-3 Integrating Spring with Struts... ■Chapter 12: Spring Roo 501 12-1 Setting Up the Spring Roo Development Environment 503 Problem 503 Solution 503 How It Works 503 12-2 Creating Your First Spring Roo Project 506 Problem 506 Solution 506 How It Works 506 12-3 Importing an Existing Project into SpringSource... 231 6-4 Integrating Spring with JSF 237 Problem 237 Solution 237 How It Works 238 6-5 Integrating Spring with DWR 244 Problem 244 Solution 244 How It Works 244 Summary 248 xiv www.it-ebooks.info ■ CONTENTS ■Chapter 7: Spring Web Flow 249 7-1... 275 7-5 Integrating Spring Web Flow with JSF 283 Problem 283 Solution 283 How It Works 283 7-6 Using RichFaces with Spring Web Flow 291 Problem 291 Solution 291 Approach 291 Summary 295 xv www.it-ebooks.info ■ CONTENTS ■Chapter 8: Spring @MVC 297... 359 Solution 359 How It Works 359 8-13 Creating Excel and PDF Views 362 Problem 362 Solution 362 How It Works 362 Summary 369 ■Chapter 9: Spring REST 371 9-1 Publishing a REST Service with Spring 371 Problem 371 Solution 371 How It Works... 143 3-10 Load-Time Weaving AspectJ Aspects in Spring 146 Problem 146 Solution 146 How It Works 147 3-11 Configuring AspectJ Aspects in Spring 152 Problem 152 Solution 152 How It Works 153 3-12 Injecting Spring Beans into Domain Objects 154 Problem ... Solution 561 How It Works 562 13-8 Using Spring s Common Testing Annotations 565 Problem 565 Solution 565 How It Works 566 Summary 568 ■Chapter 14: Spring Portlet MVC Framework 569 14-1 Developing a Simple Portlet with Spring Portlet MVC 569 Problem 569 Solution ... EJB, Spring Remoting, and Web Services 707 17-1 Exposing and Invoking Services Through RMI 707 Problem 707 Solution 707 How It Works 708 17-2 Creating EJB 2.x Components with Spring 711 Problem 711 Solution 712 How It Works 712 17-3 Accessing Legacy EJB 2.x Components in Spring. .. ■Chapter 18: Spring in the Enterprise 765 18-1 Exporting Spring Beans as JMX MBeans 765 Problem 765 Solution 766 How It Works 766 18-2 Publishing and Listening to JMX Notifications 778 Problem 778 Solution 778 How It Works 778 18-3 Accessing Remote JMX MBeans in Spring ... Works 780 18-4 Sending E-mail with Spring s E-mail Support 783 Problem 783 Solution 784 How It Works 784 18-5 Scheduling with Spring s Quartz Support 792 Problem 792 Solution 792 How It Works 792 18-6 Scheduling With Spring 3.0’s Scheduling Namespace 797 Problem . Approach www.it-ebooks.info www.it-ebooks.info Spring Recipes Second Edition ■ ■ ■ Gary Mak Josh Long Daniel Rubio www.it-ebooks.info Spring Recipes, Second Edition. Long, and Daniel Rubio Covers Spring Framework 3 Learn to use the full power of Spring 3 through coding recipes! SECOND EDITION Spring Recipes A Problem-Solution

Ngày đăng: 24/03/2014, 02:20

TỪ KHÓA LIÊN QUAN