Professional Java™ Development with the Spring Framework
Wiley Publishing, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
Copyright © 2005 by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
Library of Congress Cataloging-in-Publication Data:
Professional Java development with the Spring Framework/Rod Johnson
ISBN-13: 978-0-7645-7483-2 (paper/website)
ISBN-10: 0-7645-7483-3 (paper/website)
1. Java (Computer program language) 2. Application software
–Development. I. Johnson, Rod, Ph.D.
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN THEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Java is a trademark of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books.
About the Authors
Rod Johnson is the founder of the Spring Framework and a well-known expert on Java and J2EE.
Rod holds a Ph.D. from Sydney University. Originally from a C/C++ background, he has been involved with Java and J2EE since their releases as a developer, architect, and consultant.
He is the author of two of the most popular and influential books on J2EE: Expert One-on-One J2EE Design and Development (Wrox, 2002), and J2EE without EJB (Wrox, 2004, with Juergen Hoeller). Both have played a major role in the rise of "agile" J2EE, and the move away from overly complex traditional J2EE architecture.
Rod is co-lead of the Spring Framework. He is a popular conference speaker and regularly appears at leading Java events in the US, Europe, and Asia. He serves in the Java Community Process (JCP) on the expert groups of several JSRs.
He also has wide consulting experience in banking and finance, insurance, software, and media. He is CEO of Interface21 (www.interface21.com), a consultancy devoted to providing expert J2EE and Spring Framework services. He is actively involved with client projects as well as Spring development.
Juergen Hoeller is co-founder of Interface21, the company providing commercial Spring services from the source. He is a key driver of Spring development and has been release manager since Spring's inception. His special interests and responsibilities in the project cover a wide variety of topics, from the core container to transaction management, data access, and lightweight remoting.
Juergen has a Master's degree in computer science from the University of Linz, specializing in Java, OO modeling, and software engineering. He is co-author of Expert One-on-One J2EE Development without EJB (Wiley, 2004) and regularly presents at conferences and other events. He is also active in many community forums, including TheServerSide.
To Eva, for her continuing love and support, and for understanding that there is no separation between working time and spare time in the Spring world.
Alef Arendsen studied computer sciences at the University of Utrecht. Later, also in Utrecht, Alef started his first company. After this turned out to be too little a challenge, Alef went to work for SmartHaven, an Amsterdam-based VC- funded company providing J2EE components for knowledge management applications. He was responsible for streamlining the development process and designing parts of the component infrastructure. In early 2002, together with Joost van de Wijgerd, Alef founded JTeam, a software company providing J2EE development services. Alef is a core Spring committer and, while remaining involved with JTeam, he is now a consultant for Interface21. He is a frequent speaker at public conferences. Alef can be reached by email at email@example.com. You can also read his blog at http://blog.arendsen.net.
To Mas, my nephew, who frequently cheered me up and reminded me of things other than work.
Thomas Risberg is a database developer working for TargetrRx, a pharmaceutical market research company located in Horsham, Pennsylvania. He has many years of experience working with both large and small organizations on various database-related projects ranging from simple data entry programs to large data warehousing implementations. Thomas is a reformed COBOL programmer who came to Java via Xbase, Visual Basic, and PL/SQL. He served as an Oracle DBA for a couple of years but decided that software development was really where his heart was.
Thomas has a B.A. degree in information processing from the University of Stockhom, Sweden. He is a certified Oracle Professional DBA and a Sun Certified Java Programmer and J2EE Architect.
Thomas joined the Spring Framework development team in early 2003 and is mostly involved in evolving the JDBC layer. His non-computer–related interests are soccer, photography, and travel.
Colin Sampaleanu has had a long and varied career spanning almost two decades—after a childhood spent tinkering with computers and software—including experience developing for and managing his own retail software company, other years in the C++ shrinkwrap and enterprise software space, experience with Java since the early days of the language, and a complete focus on enterprise Java since the late nineties.
Colin is a currently a principal partner at Interface21, which specializes in Spring training, consulting, and support. Prior to joining Interface21, Colin was Chief Architect at a software incubator / VC.
As a core Spring developer and Interface21 principal, Colin spends much of his time talking and writing about the benefits of Spring, and promoting agile software development architectures and methodologies in general.
To Nina, for her continued love and support, and for understanding that despite our best intentions, in this field 9–5 is often just the first half of the workday. To Alec and Maia, for their simple innocence and joy, and for reminding me that there are other things in life besides computers.
Adaobi Obi Tulton
Peter den Haan
Mary Beth Wakefield
Vice President & Executive Group Publisher
Vice President and Publisher
Joseph B. Wikert
Graphics and Production Specialists
Quality Control Technicians
Carl William Pierce
Proofreading and Indexing
TECHBOOKS Production Services
Rod Johnson: Many people helped in the writing of this book. In particular, I thank my co-authors, each of whom played a valuable role in ensuring that we were able to achieve coverage of a wide range of Spring's large and growing feature set.
Thanks to Ben Alex, lead developer of Acegi Security for Spring, for contributing most of the material on Spring security. Mark Pollack, Spring developer and lead of Spring.NET, also kindly contributed valuable material relating to
Spring's services for JMS. Dmitriy Kopylenko, also a Spring developer, helped with UML diagrams and examples for the AOP chapter.
Finally, thanks to the reviewers—especially Peter den Haan and Aleksander Seovic—for their attention to detail and many valuable suggestions.
Juergen Hoeller: I thank my co-authors, our reviewers, and our editor; it has been a pleasure working with you. A special thank you goes to Peter den Haan for his extraordinarily thorough chapter reviews. Last but not least, I express my gratitude to the entire Spring community: Without your active participation, the Spring project would not be what it is today.
A. Arendsen: I thank all my co-workers at JTeam for their support. Special thanks to Bram Smeets and Arjen Poutsma for providing valuable content on various topics. I also owe a lot to Joost, the chap I originally started JTeam with. Without him I couldn't have found the time to contribute to this book. I also want to express my gratitude to Goof Kerling, who taught me a great deal about programming, how to do it the right way, and life in general. Thanks to Lars for cooking once every month, providing me with a place to stay until my house was finished, and joining me for the occasional beer. Also, thanks to my family for their support and the technical editors for thoroughly reviewing the content and for pointing out that Dutch isn't the most widely used language in the world.
Thomas Risberg: I thank the entire Spring community—without you, neither the project nor this book would be what it is today.
Colin Sampaleanu: I thank my co-authors, my partners at Interface21, and the Spring team for setting the bar so high. It's always a pleasure working with you. I'm grateful for the many colleagues over the years who by being passionate about the art of software development have helped keep my own interest high. I also thank my technical reviewers, Peter den Haan, Qi Zhang, and Jim Leask, who provided much valuable feedback.