Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Bắt đầu với Sping
Nội dung xem thử
Mô tả chi tiết
this print for content only—size & color not accurate spine = 0.693" 296 page count
EMPOWERING PRODUCTIVITY FOR THE JAVA™ DEVELOPER
Beginning Spring 2:
From Novice to Professional
Dear Reader,
Over the last few years, the Java™ application development space has been
flooded with tools and frameworks. The Spring framework is an agile, open
source toolkit for knitting together disparate libraries and tools into powerful
enterprise Java applications. Spring has a distinct, consistent design philosophy that has been applied carefully to all of its various libraries and wrappers.
Once you understand the Spring approach, you will be able to get up to speed
very quickly with unfamiliar components.
I’m an enthusiastic full-time developer of Spring-based Java applications. In
this book, I show you how to use Spring, but I also show you how it makes your
code easier to write, simpler to test, and as a result more reliable and supportable. I explain how to use the core features of Spring to build complex applications, and how the Spring philosophy applies to the vast array of external
software that it supports. By providing a simple but complete sample application, the book places the various features in context and provides you with a
solid basis for further exploration.
The examples I use include everything that you will need in the course of
creating a typical web application, so you will see how to apply the latest Spring
features to produce web output with Spring MVC and Spring Web Flow, how to
send e-mail by using Spring’s wrappers for the JavaMail APIs, and how to secure
your application with the Acegi libraries. I have also devoted a chapter to the
creation of unit tests for applications written using Spring.
I hope you enjoy reading this book as much as I enjoyed writing it.
Dave Minter
Author of
Beginning Hibernate
Pro Hibernate 3
Building Portals with
the Java Portlet API
US $39.99
Shelve in
Java Programming
User level:
Beginner–Intermediate
Minter Beginning Spring 2
The EXPERT’s VOIce® in Java™ Technology
Beginning
Spring 2
From Novice to Professional
CYAN
MAGENTA
YELLOW
BLACK
PANTONE 123 C
Dave Minter
Companion
eBook
Available
THE APRESS JAVA™ ROADMAP
Expert Spring MVC
and Web Flow
Building Spring 2
Enterprise Applications
Spring 2 Recipes
Beginning Spring 2
www.apress.com
java.apress.com
SOURCE CODE ONLINE
Companion eBook
See last page for details
on $10 eBook version
ISBN-13: 978-1-59059-685-2
ISBN-10: 1-59059-685-4
9 781590 596852
5 3 9 9 9
Learn to build powerful enterprise Java™
applications using the Spring Framework
Beginning Spring 2
From Novice to Professional
■■■
Dave Minter
Minter_685-4FRONT.fm Page i Wednesday, November 14, 2007 6:22 AM
Beginning Spring 2: From Novice to Professional
Copyright © 2008 by Dave Minter
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-59059-685-2
ISBN-10 (pbk): 1-59059-685-4
ISBN-13 (electronic): 978-1-4302-0493-0
ISBN-10 (electronic): 1-4302-0493-1
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Java™ and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc., in the
U.S. and other countries. Apress, Inc., is not affiliated with Sun Microsystems, Inc., and this book was
written without endorsement from Sun Microsystems, Inc.
Lead Editor: Steve Anglin
Technical Reviewer: Kris Lander
Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick,
Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper,
Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Project Manager: Kylie Johnston
Copy Editor: Sharon Wilkey
Associate Production Director: Kari Brooks-Copony
Production Editor: Gwen Burda
Compositor: Susan Glinert Stevens
Proofreader: Linda Seifert
Indexer: Toma Mulligan
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600,
Berkeley, CA 94705. Phone 510-549-5930, fax 510-549-5939, e-mail [email protected], or visit http://
www.apress.com.
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 http://www.apress.com.
Minter_685-4FRONT.fm Page ii Wednesday, November 14, 2007 6:22 AM
To my parents
Minter_685-4FRONT.fm Page iii Wednesday, November 14, 2007 6:22 AM
Minter_685-4FRONT.fm Page iv Wednesday, November 14, 2007 6:22 AM
v
Contents at a Glance
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
■CHAPTER 1 An Introduction to Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
■CHAPTER 2 Presenting the Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
■CHAPTER 3 The Heart of Spring: Inversion of Control . . . . . . . . . . . . . . . . . . . . . . 29
■CHAPTER 4 Data Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
■CHAPTER 5 The Service Layer, Transaction Management, and AOP . . . . . . . . 75
■CHAPTER 6 Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
■CHAPTER 7 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
■CHAPTER 8 Sending E-mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
■CHAPTER 9 Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
■CHAPTER 10 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
■APPENDIX The Spring IDE Plug-in for Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Minter_685-4FRONT.fm Page v Wednesday, November 14, 2007 6:22 AM
Minter_685-4FRONT.fm Page vi Wednesday, November 14, 2007 6:22 AM
vii
Contents
About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
About the Technical Reviewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
■CHAPTER 1 An Introduction to Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Inversion of Control (IOC) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Dependency Lookup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Problem with Dependency Lookup . . . . . . . . . . . . . . . . . . . . . . . . 3
Dependency Injection as a Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Dependency Injection as an Aid to Testing . . . . . . . . . . . . . . . . . . . . . 5
An Agile Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Aspect-Oriented Programming (AOP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Spring and Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Spring MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Spring Web Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Spring Portlet MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Other Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Other Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Other Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Maven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Spring Integrated Development Environment (IDE) Plug-in . . . . . . . 11
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
■CHAPTER 2 Presenting the Sample Application . . . . . . . . . . . . . . . . . . . . . . 13
Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Architecture of the Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
The Presentation Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
The Service Layer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
The Data Access Layer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
The Database and Mail Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Contents
Minter_685-4FRONT.fm Page vii Wednesday, November 14, 2007 6:22 AM
viii ■CONTENTS
Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Scenario 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Scenario 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Maven . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Setting Up a Maven Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
The Maven Repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Obtaining Maven. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Downloading, Configuring, and Building
the Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
The Web Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
■CHAPTER 3 The Heart of Spring: Inversion of Control . . . . . . . . . . . . . . . . 29
Benefits and Disadvantages of DI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Coupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Tight Coupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Loose Coupling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Knowing When to Stop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Need for a Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
The Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
XML Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Autowiring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Bean Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Property Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Constructor Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
XML Schema–Based Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Annotation-Based Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Bean and BeanFactory Life Cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Application Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Resource Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
■CHAPTER 4 Data Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Persistence Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
DAOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Templates and Support Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Minter_685-4FRONT.fm Page viii Wednesday, November 14, 2007 6:22 AM
■CONTENTS ix
Plain Old JDBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Creating the JDBC DAO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Configuring the JDBC DAO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Hibernate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Hibernate Mappings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Hibernate Query Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Creating the Hibernate DAO. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Configuring the Hibernate DAO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Hibernate Lazy Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
■CHAPTER 5 The Service Layer, Transaction Management,
and AOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Implementing Services in Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Transactions Using Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Transactions Using XML Mappings. . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Aspect-Oriented Programming (AOP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Schema Extensions and Annotation-Based Transactions . . . . . . . . 87
Schema-Based Transaction Declaration . . . . . . . . . . . . . . . . . . . . . . 87
A Custom Aspect Implementation. . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Further Support for AOP in Spring . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
■CHAPTER 6 Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
The Model View Controller Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Managing Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Context Loader Listener. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Context Loader Servlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Other Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Spring MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Dispatchers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Mappings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Views and Resolvers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Spring Web Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Forms and Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Minter_685-4FRONT.fm Page ix Wednesday, November 14, 2007 6:22 AM
x ■CONTENTS
Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Velocity and FreeMarker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Programmatically Generated Output . . . . . . . . . . . . . . . . . . . . . . . . 128
Special View Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Tag Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Hibernate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Delegated Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Localization and Internationalization . . . . . . . . . . . . . . . . . . . . . . . . 135
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
■CHAPTER 7 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Securing the Web Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Other Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Channel Security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Making Security Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Security Tag Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Security Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Securing the Service Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
■CHAPTER 8 Sending E-mail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Using the Mail Sender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Sending Plain Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Sending Formatted HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Including Inline Images and Attachments . . . . . . . . . . . . . . . . . . . . . . . . 166
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
■CHAPTER 9 Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Remoting Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
RMI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Spring’s Own HTTP-Based Remoting Mechanism . . . . . . . . . . . . . 176
Hessian and Burlap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
SOAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
CORBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
JMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Minter_685-4FRONT.fm Page x Wednesday, November 14, 2007 6:22 AM
■CONTENTS xi
■CHAPTER 10 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Unit Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Test-Driven Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Mock Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Testing the DAO Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Testing the Service Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Testing the Presentation Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Spring Mock Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Integration Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Web Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Regression Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
■APPENDIX The Spring IDE Plug-in for Eclipse . . . . . . . . . . . . . . . . . . . . . . 229
Installing the Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Managing Bean Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Managing Spring Web Flow Configuration . . . . . . . . . . . . . . . . . . . . . . . . 238
Using File-Creation Wizards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Minter_685-4FRONT.fm Page xi Wednesday, November 14, 2007 6:22 AM
Minter_685-4FRONT.fm Page xii Wednesday, November 14, 2007 6:22 AM
xiii
About the Author
■DAVE MINTER has adored computers since he was small enough to
play in the boxes they came in. He built his first PC from discarded,
faulty, and obsolete components, and considers that to be the foundation of his career as an integration consultant. Dave lives in London,
where he helps large and small companies build systems that “just
work.” Currently he is developing a bizarre new type of web application
server for FatMoggy Ltd. He is a co-author of three other Apress books:
Building Portals with the Java Portlet API, Pro Hibernate 3, and
Beginning Hibernate.
Minter_685-4FRONT.fm Page xiii Wednesday, November 14, 2007 6:22 AM
f7670b088a34e6aa65a5685727db1ff4