logo资料库

Professional Java Development With The Spring Framework.pdf

第1页 / 共649页
第2页 / 共649页
第3页 / 共649页
第4页 / 共649页
第5页 / 共649页
第6页 / 共649页
第7页 / 共649页
第8页 / 共649页
资料共649页,剩余部分请下载后查看
Table of Contents
Back Cover
Professional Java Development with the Spring Framework
Introduction
Aims of This Book
What This Book Covers
Assumed Knowledge
Recommended Reading
What You Need to Use This Book
The Sample Application
Conventions
Source Code
Errata
p2p.wrox.com
Chapter 1: Introducing the Spring Framework
Spring's Values
Spring in Context
Architecting Applications with Spring
The Future
The Spring Project and Community
Summary
Chapter 2: The Bean Factory and Application Context
Inversion of Control and Dependency Injection
The Container
Summary
Chapter 3: Advanced Container Concepts
Abstractions for Low-Level Resources
Application Events
Managing the Container
Some Convenience Factor y Beans
Proper ty Editors Provided by Spring
Strategies for Testing
Alternatives to XML
References
Summary
Chapter 4: Spring and AOP
Goals
Assumptions
Example
Spring's AOP Framework
Using Advanced Features of Spring's AOP Framework
Integration with Other AOP Frameworks
References
Summary
Chapter 5: DAO Support and JDBC Framework
The Data Access Object Pattern
Introducing Spring's JDBC Framework
Building the Data Access Layer for the Sample Application
Operations with JdbcTemplate
Using the RDBMS Operation Classes
Advanced Concepts
Additional Considerations
Summary
Chapter 6: Transaction and Resource Management
Background
Transactions and J2EE
An Example of Spring's Transaction Suppor t
Introducing Spring's Transaction Abstraction
DataSource Declarations
Summary
Chapter 7: Object/Relational Mapping
Background
O/R Mapping Support in Spring
iBATIS SQL Maps
Hibernate
JDO
Other O/R Mapping Tools
Summary
Chapter 8: Lightweight Remoting
Concepts and Scope
Common Configuration Style
Hessian and Burlap
HTTP Invoker
RMI
Web Ser vices via JAX-RPC
Summary
Chapter 9: Supporting Services
JMS
Scheduling with Spring
Sending Email with Spring
Scripting
Summary
Chapter 10: Acegi Security System for Spring
Enterprise Application Security Choices
Acegi Security Fundamentals
Example Code
Summary
Chapter 11: Spring and EJB
Deciding on the Need for EJBs
Accessing EJBs
Implementing EJBs with Spring
Singleton Container Access, Good or Evil?
Testing Concerns
Summary
Chapter 12: Web MVC Framework
A Simple Example
General Architecture
Infrastructural Components
Workflow Involved with Handling Requests
Common Layout of a Spring MVC Web Application
HandlerMappings
HandlerExecutionChain and Interceptors
Handlers and Their Adapters
ModelAndView and ViewResolvers
Locale Changing and Resolution
HandlerExceptionResolvers
Controllers
Data Binding
Real-World Examples of Using Controllers
Wizard Functionality
Extending Spring's Handler Infrastructure
Uploading Files
Testing Your Controllers
Summary
Chapter 13: Web View Technologies
An Example
Considerations When Choosing a Technology
View Objects and Models
Features Offered by the AbstractView
JavaSer ver Pages
Velocity and FreeMarker
Tiles
Views Based on XML and XSLT
Excel and Other Document-Based Views
Implementing Custom Views
Summary
Chapter 14: Integrating with Other Web Frameworks
Considerations When Choosing an MVC Framework
Integrating with Spring: Core Concepts
WebWork Integration
Struts Integration
Tapestry Integration
JavaServer Faces Integration
Summary
Chapter 15: The Sample Application
Choice of Server Technologies
Application Layers
Persistence Layer
Business Ser vice Layer
Web Layer
Comparison with the J2EE Design and Development Implementation
Ser ver Configuration
Build and Deployment
Summary
Chapter 16: Conclusion
The Spring Solution
Guidelines for Spring Development
Related Projects
Spring in Non-J2EE Environments
To Find Out More
The Future
Appendix A: Requirements for the Sample Application
Overview
User Populations
Assumptions
Scope Limitations
Delivery Schedule
Internet User Interface
Non-Functional Requirements
Hardware and Software Environment
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
List of Figures
List of Sidebars
Professional Java Development with the Spring Framework byRod Johnsonet al. John Wiley & Sons 2005 (672 pages) ISBN:0764574833 Written by the lead developers of the Spring Framework, this authoritative guide shows you not only what spring can do but why, explaining its functionality and motivation to help you use all parts of the framework to develop successful applications. Table of Contents Professional Java Development with the Spring Framework Introduction Chapter 1 - Introducing the Spring Framework Chapter 2 - The Bean Factory and Application Context Chapter 3 - Advanced Container Concepts Chapter 4 - Spring and AOP Chapter 5 - DAO Support and JDBC Framework Chapter 6 - Transaction and Resource Management Chapter 7 - Object/Relational Mapping Chapter 8 - Lightweight Remoting Chapter 9 - Supporting Services Chapter 10 - Acegi Security System for Spring Chapter 11 - Spring and EJB Chapter 12 - Web MVC Framework Chapter 13 - Web View Technologies Chapter 14 - Integrating with Other Web Frameworks Chapter 15 - The Sample Application Chapter 16 - Conclusion Appendix A - Requirements for the Sample Application Index List of Figures List of Sidebars
Back Cover The Spring Framework is a major open source application development framework that makes Java/J2EE development easier and more productive. This book shows you not only what spring can do but why, explaining its functionality and motivation to help you use all parts of the framework to develop successful applications. You will be guided through all the Spring features and see how they form a coherent whole. In turn, this will help you understand the rationale for Spring’s approach, when to use Spring, and how to follow best practices. All this is illustrated with a complete sample application. When you finish the book, you will be well equipped to use Spring effectively in everything from simple Web applications to complex enterprise applications. What you will learn from this book The core Inversion of Control container and the concept of Dependency Injection Spring’s Aspect Oriented Programming (AOP) framework and why AOP is important in J2EE development How to use Spring’s programmatic and declarative transaction management services effectively Ways to access data using Spring’s JDBC functionality, iBATIS SQL Maps, Hibernate, and other O/R mapping frameworks Spring services for accessing and implementing EJBs Spring’s remoting framework
Professional Java Development with the Spring Framework Rod Johnson Juergen Hoeller Alef Arendsen Thomas Risberg Colin Sampaleanu Professional Java™ Development with the Spring Framework Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2005 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN-13: 978-0-7645-7483-2 ISBN-10: 0-7645-7483-3 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/RV/QW/QV/IN Library of Congress Cataloging-in-Publication Data: Professional Java development with the Spring Framework/Rod Johnson ...[et al.]. p. cm. Includes index. 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. QA76.73.J38P74585 2005 005.13'3–dc22 2005013970 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. For Kerry. 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 alef@interface21.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. Credits Executive Editor Robert Elliott Development Editor Adaobi Obi Tulton Technical Editors Peter den Haan Qi Zhang Aleksandar Seovic Erik Janssens Copy Editor Nancy Rapoport Editorial Manager Mary Beth Wakefield Vice President & Executive Group Publisher Richard Swadley Vice President and Publisher
Joseph B. Wikert Project Coordinator Kristie Rees Graphics and Production Specialists April Farling Julie Trippetti Quality Control Technicians Leeann Harney Jessica Kramer Joe Niesen, Carl William Pierce Proofreading and Indexing TECHBOOKS Production Services Acknowledgments 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.
Introduction The Spring Framework is a major open source application development framework that makes Java/J2EE development easier and more productive. Spring offers services that you can use in a wide range of environments, from applets and standalone clients through web applications running in a simple servlet engine to complex enterprise applications running in a full-blown J2EE application server. Spring enables a POJO programming model that decouples your code from its environment, protecting your investment in the face of change. Spring works on JDK 1.3 and later, taking advantage of JDK 1.4 and 1.5 features if available. Spring's J2EE services run on J2EE 1.2 and later. This book will show you how you can use all the major parts of Spring to help you develop successful applications. You'll learn not just what Spring does, but why. You will gain insight into best practices when using the framework, and you will see a complete sample application. Whom This Book Is For This book is for Java/J2EE architects and developers who want to gain a deep knowledge of the Spring Framework in order to use it effectively in applications from simple web applications up to complex enterprise applications. If you're new to Spring, you will still be able to work your way through this book. However, the coverage of advanced topics will ensure that even experienced Spring users will find information to help them use Spring effectively. You will probably want to keep this book on your desk for reference as you develop applications using Spring.
Aims of This Book This book covers all major parts of the Spring framework, explaining the framework's functionality and motivation. It aims to equip you to implement advanced applications using Spring.
分享到:
收藏