Search and Find
Service
Title Page
1
Copyright Page
2
Contents at a Glance
4
Table of Contents
6
About the Authors
37
About the Technical Reviewers
38
Acknowledgments
39
Introduction
41
Who This Book Is For
41
How This Book Is Structured
41
Conventions
43
Prerequisites
43
Downloading the code
44
Contacting the Authors
44
CHAPTER 1 Introduction to Spring
45
1-1. Instantiating the Spring IoC Container
45
Problem
45
Solution
45
How It Works
47
Instantiating an Application Context
47
Getting Beans from the IoC Container
47
1-2. Configuring Beans in the Spring IoC Container
48
Problem
48
Solution
48
How It Works
49
Creating the Bean Class
49
Creating the Bean Configuration File
50
Declaring Beans in the Bean Configuration File
50
Defining Bean Properties by Shortcut
51
Configuring Collections for Your Beans
52
Lists, Arrays, and Sets
52
Maps and Properties
55
1-3. Creating Beans by Invoking a Constructor
58
Problem
58
Solution
59
How It Works
59
1-4. Resolving Constructor Ambiguity
62
Problem
62
Solution
62
How It Works
62
1-5. Specifying Bean References
65
Problem
65
Solution
65
How It Works
65
Specifying Bean References for Setter Methods
66
Specifying Bean References for Constructor Arguments
68
Declaring Inner Beans
68
1-6. Specifying the Data Type for Collection Elements
69
Problem
69
Solution
69
How It Works
69
1-7. Creating Beans Using Spring’s FactoryBean
72
Problem
72
Solution
72
How It Works
72
1-8. Defining Collections Using Factory Beans and the Utility Schema
74
Problem
74
Solution
74
How It Works
74
Specifying the Concrete Class for Collections
74
Defining Stand-Alone Collections
75
1-9. Checking Properties with Dependency Checking
76
Problem
76
Solution
76
How It Works
77
Checking Properties of the Simple Types
77
Checking Properties of the Object Types
78
Checking Properties of All Types
78
Dependency Checking and Constructor Injection
79
1-10. Checking Properties with the @Required Annotation
79
Problem
79
Solution
79
How It Works
79
1-11. Auto-Wiring Beans with XML Configuration
82
Problem
82
Solution
82
How It Works
83
Auto-Wiring by Type
83
Auto-Wiring by Name
84
Auto-Wiring by Constructor
84
Auto-Wiring by Auto-Detection
85
Auto-Wiring and Dependency Checking
86
1-12. Auto-Wiring Beans with @Autowired and @Resource
86
Problem
86
Solution
86
How It Works
87
Auto-Wiring a Single Bean of Compatible Type
87
Auto-Wiring All Beans of Compatible Type
89
Auto-Wiring by Type with Qualifiers
90
Auto-Wiring by Name
92
1-13. Inheriting Bean Configuration
93
Problem
93
Solution
93
How It Works
94
1-14. Scanning Components from the Classpath
97
Problem
97
Solution
97
How It Works
97
Scanning Components Automatically
99
Filtering Components to Scan
101
Naming Detected Components
102
Summary
102
CHAPTER 2 Advanced Spring IoC Container
104
2-1. Creating Beans by Invoking a Static Factory Method
104
Problem
104
Solution
104
How It Works
104
2-2. Creating Beans by Invoking an Instance Factory Method
105
Problem
105
Solution
106
How It Works
106
2-3. Declaring Beans from Static Fields
107
Problem
107
Solution
107
How It Works
107
2-4. Declaring Beans from Object Properties
109
Problem
109
Solution
109
How It Works
109
2-5. Using the Spring Expression Language
111
Problem
111
Solution
111
How It Works
111
Features of the Language Syntax
112
Uses of the Language in Your Configurations
114
Using the Spring Expression Language Parser
115
2-6. Setting Bean Scopes
117
Problem
117
Solution
117
How It Works
117
2-7. Customizing Bean Initialization and Destruction
120
Problem
120
Solution
120
How It Works
120
Implementing the InitializingBean and DisposableBean Interfaces
122
Setting the init-method and destroy-method Attributes
123
Annotating the @PostConstruct and @PreDestroy Annotations
123
2-8. Reducing XML Configuration with Java Config
125
Problem
125
Solution
125
How It Works
125
2-9. Making Beans Aware of the Container
129
Problem
129
Solution
129
How It Works
130
2-10. Loading External Resources
131
Problem
131
Solution
131
How It Works
132
Resource Prefixes
133
Injecting Resources
133
2-11. Creating Bean Post Processors
134
Problem
134
Solution
134
How It Works
135
2-12. Externalizing Bean Configurations
138
Problem
138
Solution
138
How It Works
138
2-13. Resolving Text Messages
139
Problem
139
Solution
140
How It Works
140
2-14. Communicating with Application Events
142
Problem
142
Solution
142
How It Works
142
Defining Events
142
Publishing Events
143
Listening to Events
144
2-15. Registering Property Editors in Spring
145
Problem
145
Solution
145
How It Works
145
2-16. Creating Custom Property Editors
148
Problem
148
Solution
148
How It Works
148
2-17. Concurrency with TaskExecutors
150
Problem
150
Solution
150
How It Works
150
Java SE
150
Java EE
153
Spring’s Solution
154
Summary
159
CHAPTER 3 Spring AOP and AspectJ Support
160
3-1. Enabling AspectJ Annotation Support in Spring
160
Problem
160
Solution
161
How It Works
161
3-2. Declaring Aspects with AspectJ Annotations
163
Problem
163
Solution
163
How It Works
164
Before Advices
164
After Advices
166
After Returning Advices
166
After Throwing Advices
167
Around Advices
168
3-3. Accessing the Join Point Information
169
Problem
169
Solution
170
How It Works
170
3-4. Specifying Aspect Precedence
171
Problem
171
Solution
171
How It Works
171
3-5. Reusing Pointcut Definitions
173
Problem
173
Solution
173
How It Works
173
3-6. Writing AspectJ Pointcut Expressions
175
Problem
175
Solution
175
How It Works
176
Method Signature Patterns
176
Type Signature Patterns
178
Bean Name Patterns
179
Combining Pointcut Expressions
179
Declaring Pointcut Parameters
180
3-7. Introducing Behaviors to Your Beans
181
Problem
181
Solution
181
How It Works
181
3-8. Introducing States to Your Beans
184
Problem
184
Solution
184
How It Works
184
3-9. Declaring Aspects with XML-Based Configurations
186
Problem
186
Solution
186
How It Works
186
Declaring Aspects
187
Declaring Pointcuts
187
Declaring Advices
188
Declaring Introductions
188
3-10. Load-Time Weaving AspectJ Aspects in Spring
189
Problem
189
Solution
189
How It Works
190
Load-Time Weaving by the AspectJ Weaver
193
Load-Time Weaving by Spring Load-Time Weaver
194
3-11. Configuring AspectJ Aspects in Spring
195
Problem
195
Solution
195
How It Works
196
3-12. Injecting Spring Beans into Domain Objects
197
Problem
197
Solution
197
How It Works
197
Summary
201
CHAPTER 4 Scripting in Spring
202
19-1. Implementing Beans with Scripting Languages
202
Problem
202
Solution
202
How It Works
203
Scripting Beans with JRuby
203
Scripting Beans with Groovy
205
Scripting Beans with BeanShell
206
19-2. Injecting Spring Beans into Scripts
207
Problem
207
Solution
207
How It Works
207
Injecting Spring Beans into JRuby
209
Injecting Spring Beans into Groovy
209
Injecting Spring Beans into BeanShell
210
19-3. Refreshing Beans from Scripts
210
Problem
210
Solution
210
How It Works
211
19-4. Defining Script Sources Inline
211
Problem
211
Solution
211
How It Works
212
Summary
213
CHAPTER 5 Spring Security
214
5-1. Securing URL Access
215
Problem
215
Solution
215
How It Works
216
Setting Up a Spring MVC Application That Uses Spring Security
217
Creating the Configuration Files
218
Creating the Controllers and Page Views
220
Securing URL Access
223
5-2. Logging In to Web Applications
226
Problem
226
Solution
226
How It Works
226
HTTP Basic Authentication
226
Form-Based Login
227
The Logout Service
229
Anonymous Login
230
Remember-Me Support
230
5-3. Authenticating Users
230
Problem
230
Solution
231
How It Works
231
Authenticating Users with In-Memory Definitions
231
Authenticating Users Against a Database
232
Encrypting Passwords
235
Authenticating Users Against an LDAP Repository
237
Caching User Details
241
5-4. Making Access Control Decisions
242
Problem
242
Solution
243
How It Works
243
5-5. Securing Method Invocations
246
Problem
246
Solution
246
How It Works
246
Securing Methods by Embedding a Security Interceptor
246
Securing Methods with Pointcuts
247
Securing Methods with Annotations
248
5-6. Handling Security in Views
249
Problem
249
Solution
249
How It Works
249
Displaying Authentication Information
249
Rendering View Contents Conditionally
250
5-7. Handling Domain Object Security
251
Problem
251
Solution
251
How It Works
252
Setting Up an ACL Service
252
Maintaining ACLs for Domain Objects
255
Making Access Control Decisions Based on ACLs
257
Handling Domain Objects Returned from Methods
259
Summary
261
CHAPTER 6 Integrating Spring with Other Web Frameworks
262
6-1. Accessing Spring in Generic Web Applications
263
Problem
263
Solution
263
How It Works
263
6-2. Using Spring in Your Servlets and Filters
267
Problem
267
Solution
268
How It Works
268
Servlets
268
Filters
270
6-3. Integrating Spring with Struts 1.x
273
Problem
273
Solution
273
How It Works
274
Loading Spring’s Application Context into a Struts Application
275
Accessing Spring’s Application Context in Struts Actions
276
Declaring Struts Actions in Spring’s Bean Configuration File
278
6-4. Integrating Spring with JSF
280
Problem
280
Solution
280
How It Works
281
Resolving Spring Beans in JSF
285
Declaring JSF Managed Beans in Spring’s Bean Configuration File
286
6-5. Integrating Spring with DWR
287
Problem
287
Solution
287
How It Works
287
Exposing Spring Beans for Remote Invocation
289
Configuring DWR in Spring’s Bean Configuration File
290
Summary
291
CHAPTER 7 Spring Web Flow
292
7-1. Managing a Simple UI Flow with Spring Web Flow
292
Problem
292
Solution
292
How It Works
293
Setting Up a Spring MVC Application That Uses Spring Web Flow
294
Creating the Configuration Files
296
Creating Web Flow Definitions
299
Creating the Page Views
300
7-2. Modeling Web Flows with Different State Types
301
Problem
301
Solution
302
How It Works
302
Defining View States
305
Defining Action States
309
Defining Decision States
311
Defining End States
312
Defining Subflow States
313
7-3. Securing Web Flows
315
Problem
315
Solution
316
How It Works
316
7-4. Persisting Objects in Web Flows
318
Problem
318
Solution
318
How It Works
318
Configuring JPA in Spring’s Application Context
320
Setting Up JPA for Spring Web Flow
321
Using JPA in Web Flows
322
7-5. Integrating Spring Web Flow with JSF
326
Problem
326
Solution
326
How It Works
326
Rendering JSF Views for Spring Web Flow
326
Actions and ActionListeners
331
Using the JSF Components of Spring Faces
332
7-6. Using RichFaces with Spring Web Flow
334
Problem
334
Solution
334
Approach
334
Setting Up RichFaces With JSF
334
Summary
338
CHAPTER 8 Spring @MVC
339
8-1. Developing a Simple Web Application with Spring MVC
339
Problem
339
Solution
339
How It Works
341
Setting up a Spring MVC Application
343
Creating the Configuration Files
344
Activating Spring MVC annotation scanning
346
Creating Spring MVC Controllers
347
Creating JSP Views
350
Deploying the Web Application
352
8-2. Mapping requests with @RequestMapping
352
Problem
352
Solution
353
How It Works
353
Mapping requests by method
353
Mapping requests by class
354
Mapping requests by HTTP request type
355
8-3. Intercepting Requests with Handler Interceptors
356
Problem
356
Solution
357
How It Works
357
8-4. Resolving User Locales
360
Problem
360
Solution
361
How It Works
361
Resolving Locales by an HTTP Request Header
361
Resolving Locales by a Session Attribute
361
Resolving Locales by a Cookie
361
Changing a User’s Locale
362
8-5. Externalizing Locale-Sensitive Text Messages
363
Problem
363
Solution
363
How It Works
363
8-6. Resolving Views by Names
364
Problem
364
Solution
364
How It Works
365
Resolving Views Based on a template’s name and location
365
Resolving Views from an XML Configuration File
365
Resolving Views from a Resource Bundle
366
Resolving Views with Multiple Resolvers
366
The Redirect Prefix
367
8-7. Views and Content Negotiation
367
Problem
367
Solution
368
How It Works
368
8-8. Mapping Exceptions to Views
371
Problem
371
Solution
371
How It Works
371
8-9. Assigning values in a Controller with @Value
373
Problem
373
Solution
373
How It Works
373
8-10. Handling Forms with Controllers
375
Problem
375
Solution
375
How It Works
375
Creating a form’s views
376
Creating a form’s service processing
378
Creating a form’s controller
378
Initializing a model attribute object and pre-populating a form with values
380
Providing form Reference Data
382
Binding Properties of Custom Types
384
Validating Form Data
386
Expiring a controller’s Session Data
389
8-11. Handling Multipage Forms with Wizard Form Controllers
390
Problem
390
Solution
390
How It Works
391
Creating Wizard Form Pages
392
Creating a Wizard Form Controller
395
Validating Wizard Form Data
398
8-12. Bean validation with Annotations (JSR-303)
401
Problem
401
Solution
401
How It Works
401
8-13. Creating Excel and PDF Views
404
Problem
404
Solution
404
How It Works
404
Creating Excel Views
406
Creating PDF Views
407
Creating resolvers for Excel and PDF views
409
Creating date based PDF and XLS file names
409
Summary
411
CHAPTER 9 Spring REST
412
9-1. Publishing a REST Service with Spring
412
Problem
412
Solution
412
How It Works
413
9-2. Accessing a REST Service with Spring
417
Problem
417
Solution
417
How It Works
418
9-3. Publishing RSS and Atom feeds
422
Problem
422
Solution
422
How It Works
423
9-4. Publishing JSON with REST services
432
Problem
432
Solution
432
How It Works
433
9-5. Accessing REST Services with Elaborate XML Responses
435
Problem
435
Solution
435
How It Works
435
Summary
445
CHAPTER 10 Spring and Flex
446
10-1. Getting started with Flex
447
Problem
447
Solution
448
How It Works
448
Flex Development Basics
448
The Tools
452
10-2. Leaving the Sandbox
453
Problem
453
Solution
453
How It Works
454
FlashVars
454
ExternalInterface
455
HTTP and HTTPS
458
Consuming SOAP Services
461
Flash Remoting with AMF
463
10-3. Adding the Spring BlazeDS support to an application
465
Problem
465
Solution
465
How It Works
466
Installing the Spring Support
466
10-4. Exposing Services Through BlazeDS / Spring
471
Problem
471
Solution
471
How It Works
471
10-5. Working With Server-Side Objects
478
Problem
478
Solution
478
How It Works
478
10-6. Consuming Message-Oriented Services Using BlazeDS and Spring
481
Problem
481
Solution
482
How It Works
482
JMS
485
Spring Integration
486
BlazeDS
491
Sending Messages from Flex
492
10-7. Bringing Dependency Injection to your ActionScript Client
493
Problem
493
Solution
494
How It Works
494
Summary
498
CHAPTER 11 Grails
499
11-1. Getting and Installing Grails
499
Problem
499
Solution
499
How It Works
500
11-2. Creating a Grails Application
500
Problem
500
Solution
501
How It Works
501
A Grails Application’s File and Directory Structure
502
Running an Application
503
Creating Your First Grails Application Construct
504
Exporting a Grails Application to a WAR
505
11-3. Grails Plug-Ins
506
Problem
506
Solution
506
How It Works
507
11-4. Developing, Producing, and Testing in Grails Environments
508
Problem
508
Solution
508
How It Works
508
11-5. Creating an Application’s Domain Classes
510
Problem
510
Solution
511
How It Works
511
11-6. Generating CRUD Controllers and Views for an Application’s Domain Classes
513
Problem
513
Solution
513
How It Works
513
11-7. Internationalization (I18n) Message Properties
517
Problem
517
Solution
517
How it works
517
11-8. Changing Permanent Storage Systems
520
Problem
520
Solution
520
How It Works
520
Setting Up an RDBMS Driver
521
Configuring an RDBMS Instance
521
11-9. Logging
523
Problem
523
Solution
523
How It Works
523
Configuring Custom Appenders and Loggers
524
Configuring Layouts
526
11-10. Running Unit and Integration Tests
526
Problem
526
Solution
526
How It Works
527
11-11. Using Custom Layouts and Templates
532
Problem
532
Solution
532
How It Works
532
11-12. Using GORM Queries
535
Problem
535
Solution
535
How It Works
535
11-13. Creating Custom Tags
537
Problem
537
Solution
537
How It Works
537
Summary
539
CHAPTER 12 Spring Roo
540
12-1. Setting Up the Spring Roo Development Environment
542
Problem
542
Solution
542
How It Works
542
Maven
543
SpringSource Tool Suite
543
Spring Roo
544
12-2. Creating Your First Spring Roo Project
545
Problem
545
Solution
545
How It Works
545
Exploring the Maven Project
548
Getting Started Using STS
549
12-3. Importing an Existing Project into SpringSource Tool Suite
551
Problem
551
Solution
551
How It Works
551
12-4. Building A Better Application, Quicker
553
Problem
553
Solution
554
How It Works
554
Coding the Backend
554
Coding the Front-end
558
12-5. Removing Spring Roo from Your Project
560
Problem
560
Solution
561
How It Works
561
Summary
562
CHAPTER 13 Spring Testing
563
13-1. Creating Tests with JUnit and TestNG
564
Problem
564
Solution
564
How It Works
564
Testing with JUnit 3
565
Testing with JUnit 4
567
Testing with TestNG
568
13-2. Creating Unit Tests and Integration Tests
570
Problem
570
Solution
570
How It Works
571
Creating Unit Tests for Isolated Classes
571
Creating Unit Tests for Dependent Classes Using Stubs and Mock Objects
574
Creating Integration Tests
579
13-3. Unit Testing Spring MVC Controllers
580
Problem
580
Solution
580
How It Works
580
13-4. Managing Application Contexts in Integration Tests
582
Problem
582
Solution
582
How It Works
583
Accessing the Context with JUnit 3 Legacy Support
583
Accessing the Context with the TestContext Framework in JUnit 4
585
Accessing the Context with the TestContext Framework in JUnit 3
587
Accessing the Context with the TestContext Framework in TestNG
587
13-5. Injecting Test Fixtures into Integration Tests
589
Problem
589
Solution
589
How It Works
589
Injecting Test Fixtures with JUnit 3 Legacy Support
589
Injecting Test Fixtures with the TestContext Framework in JUnit 4
590
Injecting Test Fixtures with the TestContext Framework in JUnit 3
591
Injecting Test Fixtures with the TestContext Framework in TestNG
592
13-6. Managing Transactions in Integration Tests
593
Problem
593
Solution
593
How It Works
594
Managing Transactions with JUnit 3 Legacy Support
595
Managing Transactions with the TestContext Framework in JUnit 4
596
Managing Transactions with the TestContext Framework in JUnit 3
598
Managing Transactions with the TestContext Framework in TestNG
599
13-7. Accessing a Database in Integration Tests
599
Problem
599
Solution
599
How It Works
600
Accessing a Database with JUnit 3 Legacy Support
600
Accessing a Database with the TestContext Framework
601
13-8. Using Spring’s Common Testing Annotations
603
Problem
603
Solution
603
How It Works
604
Using Common Testing Annotations with JUnit 3 Legacy Support
604
Using Common Testing Annotations with the TestContext Framework
605
Summary
606
CHAPTER 14 Spring Portlet MVC Framework
607
14-1. Developing a Simple Portlet with Spring Portlet MVC
607
Problem
607
Solution
607
How It Works
609
Setting Up a Portlet Application
609
Creating the Configuration Files
610
Creating Portlet Controllers
612
Resolving View Names into Views
614
Creating Portlet Views
614
Deploying the Portlet Application
615
14-2. Mapping Portlet Requests to Handlers
617
Problem
617
Solution
617
How It Works
617
Mapping Requests by the Portlet Mode
619
Mapping Requests by a Parameter
623
14-3. Handling Portlet Forms with Simple Form Controllers
625
Problem
625
Solution
625
How It Works
625
Creating Form Controllers
627
Validating Form Data
631
Summary
633
CHAPTER 15 Data Access
635
Problems with Direct JDBC
636
Setting Up the Application Database
636
Understanding the Data Access Object Design Pattern
638
Implementing the DAO with JDBC
638
Configuring a Data Source in Spring
640
How It Works
642
Running the DAO
643
Taking It A Step Further
644
15-1. Using a JDBC Template to Update a Database
644
Problem
644
Solution
645
How It Works
645
Updating a Database with a Statement Creator
645
Updating a Database with a Statement Setter
647
Updating a Database with a SQL Statement and Parameter Values
648
Batch Updating a Database
648
15-2. Using a JDBC Template to Query a Database
650
Problem
650
Solution
650
How It Works
650
Extracting Data with Row Callback Handler
650
Extracting Data with a Row Mapper
651
Querying for Multiple Rows
652
Querying for a Single Value
654
15-3. Simplifying JDBC Template Creation
655
Problem
655
Solution
655
How It Works
656
Injecting a JDBC Template
656
Extending the JdbcDaoSupport Class
657
15-4. Using the Simple JDBC Template with Java 1.5
658
Problem
658
Solution
658
How It Works
658
Using a Simple JDBC Template to Update a Database
658
Using a Simple JDBC Template to Query a Database
659
15-5. Using Named Parameters in a JDBC Template
662
Problem
662
Solution
662
How It Works
662
15-6. Handling Exceptions in the Spring JDBC Framework
664
Problem
664
Solution
664
How It Works
665
Understanding Exception Handling in the Spring JDBC Framework
665
Customizing Data Access Exception Handling
668
15-7. Problems with Using ORM Frameworks Directly
670
Problem
670
Solution
670
How It Works
670
Persisting Objects Using the Hibernate API with Hibernate XML Mappings
672
Persisting Objects Using the Hibernate API with JPA Annotations
675
Persisting Objects Using JPA with Hibernate as the Engine
677
15-8. Configuring ORM Resource Factories in Spring
681
Problem
681
Solution
681
How It Works
681
Configuring a Hibernate Session Factory in Spring
681
Configuring a JPA Entity Manager Factory in Spring
685
15-9. Persisting Objects with Spring’s ORM Templates
687
Problem
687
Solution
688
How It Works
688
Using a Hibernate Template and a JPA Template
688
Extending the Hibernate and JPA DAO Support Classes
692
15-10. Persisting Objects with Hibernate’s Contextual Sessions
694
Problem
694
Solution
694
How It Works
694
15-11. Persisting Objects with JPA’s Context Injection
697
Problem
697
Solution
697
How It Works
698
Summary
700
CHAPTER 16 Transaction Management in Spring
701
16-1. Problems with Transaction Management
702
Managing Transactions with JDBC Commit and Rollback
708
16-2. Choosing a Transaction Manager Implementation
709
Problem
709
Solution
709
How It Works
710
16-3. Managing Transactions Programmatically with the Transaction Manager API
711
Problem
711
Solution
711
How It Works
711
16-4. Managing Transactions Programmatically with a Transaction Template
713
Problem
713
Solution
713
How It Works
714
16-5. Managing Transactions Declaratively with Transaction Advices
716
Problem
716
Solution
717
How It Works
717
16-6. Managing Transactions Declaratively with the @Transactional Annotation
719
Problem
719
Solution
719
How It Works
720
16-7. Setting the Propagation Transaction Attribute
721
Problem
721
Solution
721
How It Works
722
The REQUIRED Propagation Behavior
724
The REQUIRES_NEW Propagation Behavior
726
Setting the Propagation Attribute in Transaction Advices, Proxies, and APIs
727
16-8. Setting the Isolation Transaction Attribute
727
Problem
727
Solution
727
How It Works
728
The READ_UNCOMMITTED and READ_COMMITTED Isolation Levels
730
The REPEATABLE_READ Isolation Level
733
The SERIALIZABLE Isolation Level
735
Setting the Isolation Level Attribute in Transaction Advices, Proxies, and APIs
736
16-9. Setting the Rollback Transaction Attribute
736
Problem
736
Solution
736
How It Works
737
16-10. Setting the Timeout and Read-Only Transaction Attributes
738
Problem
738
Solution
738
How It Works
738
16-11. Managing Transactions with Load-Time Weaving
739
Problem
739
Solution
740
How It Works
740
Summary
743
CHAPTER 17 EJB, Spring Remoting, and Web Services
744
17-1. Exposing and Invoking Services Through RMI
744
Problem
744
Solution
744
How It Works
745
Exposing an RMI Service
746
Invoking an RMI Service
747
17-2. Creating EJB 2.x Components with Spring
748
Problem
748
Solution
749
How It Works
749
Creating EJB 2.x Components Without Spring’s Support
750
Creating EJB 2.x Components with Spring’s Support
753
17-3. Accessing Legacy EJB 2.x Components in Spring
755
Problem
755
Solution
756
How It Works
756
Accessing EJB 2.x Components
757
17-4. Creating EJB 3.0 Components in Spring
760
Problem
760
Solution
760
How It Works
760
17-5. Accessing EJB 3.0 Components in Spring
762
Problem
762
Solution
762
How It Works
762
Accessing EJB 3.0 Components with Spring’s Support
762
17-6. Exposing and Invoking Services Through HTTP
764
Problem
764
Solution
764
How It Works
764
Exposing a Hessian Service
764
Invoking a Hessian Service
766
Exposing a Burlap Service
767
Invoking a Burlap Service
767
Exposing an HTTP Invoker Service
767
Invoking an HTTP Invoker Service
767
17-7. Choosing a SOAP Web Service Development Approach
768
Problem
768
Solution
768
How It Works
768
Contract-Last Web Services
768
Contract-First Web Services
769
Comparison
769
17-8. Exposing and Invoking a Contract-Last SOAP Web Services Using JAX-WS
770
Problem
770
Solution
770
How It Works
770
Exposing a Web Service Using The JAX-WS Endpoint Support in the JDK
771
Exposing a Web Service Using CXF
774
Invoking a Web Service Using CXF
776
17-9. Defining the Contract of a Web Service
777
Problem
777
Solution
777
How It Works
778
Creating Sample XML Messages
778
Generating an XSD File from Sample XML Messages
779
Optimizing the Generated XSD File
780
Previewing the Generated WSDL File
781
17-10. Implementing Web Services Using Spring-WS
782
Problem
782
Solution
782
How It Works
783
Setting Up a Spring-WS Application
783
Mapping Web Service Requests to Endpoints
784
Creating Service Endpoints
784
Publishing the WSDL File
787
17-11. Invoking Web Services Using Spring-WS
788
Problem
788
the contract. You want to use Spring-WS to create the service client.
788
How It Works
788
17-12. Developing Web Services with XML Marshalling
792
Problem
792
Solution
792
How It Works
793
Creating Service Endpoints with XML Marshalling
793
Invoking Web Services with XML Marshalling
797
17-13. Creating Service Endpoints with Annotations
798
Problem
798
Solution
798
How It Works
798
Summary
800
CHAPTER 18 Spring in the Enterprise
801
18-1. Exporting Spring Beans as JMX MBeans
801
Problem
801
Solution
802
How It Works
802
Registering MBeans Without Spring’s Support
805
Exporting Spring Beans as MBeans
807
Exposing MBeans for Remote Access
809
Assembling the Management Interface of MBeans
810
Auto-Detecting MBeans by Annotations
812
18-2. Publishing and Listening to JMX Notifications
814
Problem
814
Solution
814
How It Works
814
Publishing JMX Notifications
814
Listening to JMX Notifications
815
18-3. Accessing Remote JMX MBeans in Spring
816
Problem
816
Solution
816
How It Works
816
Accessing Remote MBeans Through an MBean Server Connection
816
Accessing Remote MBeans Through an MBean Proxy
818
18-4. Sending E-mail with Spring’s E-mail Support
819
Problem
819
Solution
820
How It Works
820
Sending E-mail Using the JavaMail API
821
Sending E-mail with Spring’s MailSender
823
Defining an E-mail Template
824
Sending MIME Messages
826
18-5. Scheduling with Spring’s Quartz Support
828
Problem
828
Solution
828
How It Works
828
Using Quartz Without Spring’s Support
828
Using Quartz with Spring’s Support
831
18-6. Scheduling With Spring 3.0’s Scheduling Namespace
833
Problem
833
Solution
833
How It Works
833
Summary
837
CHAPTER 19 Messaging
838
19-1. Sending and Receiving JMS Messages with Spring
839
Problem
839
Solution
839
How It Works
840
Sending and Receiving Messages Without Spring’s Support
841
Sending and Receiving Messages with Spring’s JMS Template
846
Sending and Receiving Messages to and from a Default Destination
849
Extending the JmsGatewaySupport Class
851
19-2. Converting JMS Messages
851
Problem
851
Solution
852
Approach
852
19-3. Managing JMS Transactions
854
Problem
854
Approach
854
Solution
854
19-4. Creating Message-Driven POJOs in Spring
856
Problem
856
Solution
856
How It Works
856
Listening for JMS Messages with Message Listeners
856
Listening for JMS Messages with POJOs
858
Converting JMS Messages
859
Managing JMS Transactions
861
Using Spring’s JMS Schema
861
19-5. Making the Connection
862
Problem
862
Solution
862
How It Works
863
Summary
863
CHAPTER 20 Spring Integration
864
20-1. Integrating One System with Another Using EAI
865
Problem
865
Solution
865
How It Works
866
Picking an Integration Style
866
Building on an ESB Solution
867
20-2. Integrating Two Systems Using JMS
868
Problem
868
Solution
868
How it Works
868
Building an Message Driven Pojo (MDP) Using Spring Integration
868
20-3. Interrogating Spring Integration Messages for Context Information
872
Problem
872
Solution
872
How it Works
873
Using MessageHeaders for Fun and Profit
873
20-4. Integrating Two Systems Using a File System
875
Problem
875
Solution
875
How It Works
876
Concerns in Dealing with a File System
876
20-5. Transforming a Message from One Type to Another
878
Problem
878
Solution
878
How It Works
878
Modifying a Message’s Payload
878
Modifying a Message’s Headers
881
20-6. Error Handling Using Spring Integration
881
Problem
881
Solution
882
How It Works
882
Routing to Custom Handlers Based on the Type of Exception
883
Building a Solution with Multiple Error Channels
884
20-7. Forking Integration Control: Splitters and Aggregators
884
Problem
884
Solution
884
How it Works
885
Using a Splitter
885
Using Aggregators
887
20-8. Conditional Routing with Routers
888
Problem
888
Solution
888
How It Works
888
20-9. Adapting External Systems to the Bus
889
Problem
889
Solution
889
How It Works
890
An Inbound Twitter Adapter
890
Twitter Messages
891
A Simple MessageSource
891
An Outbound Twitter Example
897
20-10. Staging Events Using Spring Batch
900
Problem
900
Solution
900
How It Works
900
20-11. Using Gateways
901
Problem
901
Solution
901
How It Works
902
SimpleMessagingGateway
902
Breaking the Interface Dependency
903
Summary
908
CHAPTER 21 Spring Batch
909
Runtime Metadata Model
910
21-1. Setting Up Spring Batch’s Infrastructure
911
Problem
911
Solution
911
How It Works
912
21-2. Reading and Writing (but No Arithmetic)
914
Problem
914
Solution
914
How It Works
914
The Job Configuration
916
Input
917
Output
918
21-3. Writing a Custom ItemWriter and ItemReader
919
Problem
919
Solution
919
How It Works
919
Writing a Custom ItemReader
919
Writing a Custom ItemWriter
920
21-4. Processing Input Before Writing
922
Problem
922
Solution
922
How It Works
922
Chaining Processors Together
924
21-5. Better Living through Transactions
925
Problem
925
Solution
925
How It Works
925
Transactions
925
Rollbacks
926
21-6. Retrying
927
Problem
927
Solution
927
How It Works
927
Configuring a Step
927
Retry Template
928
AOP-Based Retries
930
21-7. Controlling Step Execution
930
Problem
930
Solution
930
How It Works
931
Sequential Steps
931
Concurrency
931
Conditional Steps with Statuses
932
Conditional Steps with Decisions
934
21-8. Launching a Job
934
Problem
934
Solution
935
How It Works
935
Launching From a Web Application
936
Running from the Command Line
936
Running On A Schedule
937
21-9. Parameterizing a Job
939
Problem
939
Solution
939
How It Works
939
Launching a Job with Parameters
939
Accessing JobParameters
940
Summary
941
CHAPTER 22 Spring on the Grid
942
22-1. Clustering Object State Using Terracotta
944
Problem
944
Solution
944
How It Works
944
Deploying a Simple Example with Terracotta
945
Terracotta Architecture and Deployment
950
The XML Configuration File
951
22-2. Farming Out Execution to a Grid
954
Problem
954
Solution
954
Approach
954
Deployment
955
22-3. Load Balancing a Method
956
Problem
956
Solution
956
Approach
956
22-4. Parallelizing Processing
960
Problem
960
Solution
960
Approach
960
22-5. Deploying on GridGain
962
Problem
962
Solution
962
How It Works
962
Creating a Grid Node
962
Provisioning a Grid Node
963
Getting Access to the Spring Container from a Task
964
Node-Specific GridGain Configuration
964
Summary
967
CHAPTER 23 jBPM and Spring
968
Software Processes
969
23-1. Understanding Workflow Models
972
Problem
972
Solution
972
How It Works
972
23-2. Installing jBPM
974
Problem
974
Solution
974
How It Works
974
23-3. Integrating jBPM 4 with Spring
977
Problem
977
Solution
977
How It Works
977
The Application Context
978
23-4. Building a Service with Spring
983
Problem
983
Solution
983
How It Works
983
23-5. Building a Business Process
986
Problem
986
Solution
987
How It Works
987
Summary
989
CHAPTER 24 OSGi and Spring
991
24-1. Getting Started with OSGi
992
Problem
992
Solution
992
How It Works
992
OSGi and JavaBeans
993
The helloworld-service Service
993
Installing Equinox
996
Using the Service in a Client Bundle
996
24-2. Getting Started Using Spring Dynamic Modules
999
Problem
999
Solution
999
How It Works
999
24-3. Exporting a Service Using Spring Dynamic Modules
1003
Problem
1003
Solution
1003
How It Works
1003
Interfacing with the OSGi Runtime
1005
24-4. Finding a Specific Service in the OSGi Registry
1007
Problem
1007
Solution
1007
How It Works
1007
Ranking
1007
Service Attributes
1008
Cardinality
1009
24-5. Publishing a Service Under Multiple Interfaces
1009
Problem
1009
Solution
1009
How It Works
1010
24-6. Customizing Spring Dynamic Modules
1011
Problem
1011
Solution
1011
How It Works
1011
Making Spring Process OSGi Annotations on Beans
1011
Changing the Default HTTP Server That Spring Uses When Deploying a .war
1012
24-7. Using SpringSource dm Server
1013
Problem
1013
Solution
1013
How It Works
1013
24-8. SpringSource’s Tooling
1014
Problem
1014
Solution
1014
How it Works
1015
Summary
1015
Index
1016
All prices incl. VAT