Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

About this Book

About this Book

The Spring Framework was created with a very specific goal in mind—to make developing JEE applications easier. Along the same lines, Spring in Action was written to make learning how to use Spring easier. My goal is not to give you a blow-by-blow listing of Spring APIs. Instead, I hope to present the Spring Framework in a way that is most relevant to a JEE developer by providing practical code examples from real-world experiences.

Since Spring is a modular framework, this book was written in the same way. I recognize that not all developers have the same needs. Some may want to learn the Spring Framework from the ground up, while others may want to pick and choose different topics and go at their own pace. That way, the book can act as a tool for learning Spring for the first time as well as a guide and reference for those wanting to dig deeper into specific features.

Roadmap

Spring in Action Second Edition is divided into three parts, plus two appendices. Each of the three parts focuses on a general area of the Spring Framework: the core framework, the business and data layers, and the presentation layer. While each part builds on the previous section, each is also able to stand on its own, allowing you to dive right into a certain topic without starting from the beginning.

In part 1, you’ll explore the two core features of the Spring framework: dependency injection (DI) and aspect-oriented programming (AOP). This will give you a good understanding of Spring’s fundamentals that will be utilized throughout the book.

In chapter 1, you’ll be introduced to DI and AOP and how they lend themselves to developing loosely coupled Java applications.

Chapter 2 takes a more detailed look at how to configure and associate your application objects using dependency injection. You will learn how to write loosely coupled components and wire their dependencies and properties within the Spring container using XML.

Once you’ve got the basics of bean wiring down, you’ll be ready to look at some of the more advanced features of the Spring container in chapter 3. Among other things, you’ll learn how to hook into the lifecycle of your application components, create parent/child relationships among your bean configurations, and wire in scripted components written in Ruby and Groovy.

Chapter 4 explores how to use Spring’s AOP to decouple cross-cutting concerns from the objects that they service. This chapter also sets the stage for later chapters, where you’ll use Spring AOP to provide declarative services such as transactions, security, and caching.

Part 2 builds on the DI and AOP features introduced in part 1 and shows you how to apply these concepts in the data and business tiers of your application.

Chapter 5 covers Spring’s support for data persistence. You’ll be introduced to Spring’s JDBC support, which helps you remove much of the boilerplate code associated with JDBC. You’ll also see how Spring integrates with several popular persistence frameworks such as Hibernate, iBATIS, and the Java Persistence API (JPA).

Chapter 6 complements chapter 5, showing you how to ensure integrity in your database using Spring’s transaction support. You will see how Spring uses AOP to give simple application objects the power of declarative transactions.

In chapter 7 you will learn how to apply security to your application using Spring Security. You’ll see how Spring Security secures application both at the web request level using servlet filters and at the method level using Spring AOP.

Chapter 8 explores how to expose your application objects as remote services. You’ll also learn how to seamlessly access remote services as though they were any other object in your application. Remoting technologies explored will include RMI, Hessian/Burlap, SOAP-based web services, and Spring’s own HttpInvoker.

Although chapter 8 covers web services in Spring, chapter 9 takes a different look at web services by examining the Spring-WS project. In this chapter, you’ll learn how to use Spring-WS to build contract-first web services, in which the service’s contract is decoupled from its implementation.

Chapter 10 looks at using Spring to send and receive asynchronous messages with JMS. In addition to basic JMS operations with Spring, you’ll also learn how to using the open source Lingo project to expose and consume asynchronous remote services over JMS.

Even though Spring eliminates much of the need for EJBs, you may have a need to use both Spring and EJB together. Therefore, chapter 11 explores how to integrate Spring with EJB. You’ll learn how to write Spring-enabled EJBs, how to wire EJB references into your Spring application context, and even how to use EJB-like annotations to configure your Spring beans.

Wrapping up part 2, chapter 12 will show you how to use Spring to schedule jobs, send e-mails, access JNDI-configured resources, and manage your application objects with JMX.

Part 3 moves the discussion of Spring a little closer to the end user by looking at the ways to use Spring to build web applications.

Chapter 13 introduces you to Spring’s own MVC web framework. You will discover how Spring can transparently bind web parameters to your business objects and provide validation and error handling at the same time. You will also see how easy it is to add functionality to your web applications using Spring’s rich selection of controllers.

Picking up where chapter 13 leaves off, chapter 14 covers the view layer of Spring MVC. In this chapter, you’ll learn how to map the output of a Spring MVC controller to a specific view component for rendering to the user. You’ll see how to define application views using JSP, Velocity, FreeMarker, and Tiles. And you’ll learn how to create non-HTML output such as PDF, Excel, and RSS from Spring MVC.

Chapter 15 explores Spring Web Flow, an extension to Spring MVC that enables development of conversational web applications. In this chapter you’ll learn how to build web applications that guide the user through a specific flow.

Finally, chapter 16 shows you how to integrate Spring with other web frameworks. If you already have an investment in another web framework (or just have a preference), this chapter is for you. You’ll see how Spring provides support for several of the most popular web frameworks, including Struts, WebWork, Tapestry, and JavaServer Faces (JSF).

Appendix A will get you started with Spring, showing you how to download Spring and configure Spring in either Ant or Maven 2.

One of the key benefits of loose coupling is that it makes it easier to unit-test your application objects. Appendix B shows you how to take advantage of dependency injection and some of Spring’s test-oriented classes for testing your applications.

Additional web content

As I was writing this book, I wanted to cover as much of Spring as possible. I got a little carried away and ended up writing more than could fit into the printed book. Just like with many Hollywood movies, a lot of material ended up on the cutting room floor:

  • “Building portlet applications” This chapter covers the Spring Portlet MVC framework. Spring Portlet MVC is remarkably similar to Spring MVC (it even reuses some of Spring MVC’s classes), but is geared for the special circumstances presented by portlet applications.

  • Appendix C, “Spring XML configuration reference” This appendix documents all of the XML configuration elements available in Spring 2.0. In addition, it includes the configuration elements for Spring Web Flow and Direct Web Remoting (DWR).

  • Appendix D, “Spring JSP tag library reference” This appendix documents all of the JSP tags, both the original Spring JSP tags and the new form-binding tags from Spring 2.0.

  • Appendix E, “Spring Web Flow definition reference” This appendix catalogs all of the XML elements that are used to define a flow for Spring Web Flow.

  • Appendix F, “Customizing Spring configuration” This appendix, which was originally part of chapter 3, shows you how to create custom Spring XML configuration namespaces.

There’s some good stuff in there and I didn’t want that work to be for naught. So I convinced Manning to give it all of the same attention that it would get if it were to be printed and to make it available to download for free. You’ll be able to download this bonus material online at http://www.manning.com/SpringinAction.

Who should read this book

Spring in Action Second Edition is for all Java developers, but enterprise Java developers will find it particularly useful. While I will guide you along gently through code examples that build in complexity throughout each chapter, the true power of Spring lies in its ability to make enterprise applications easier to develop. Therefore, enterprise developers will most fully appreciate the examples presented in this book.

Because a vast portion of Spring is devoted to providing enterprise services, many parallels can be drawn between Spring and EJB. Therefore, any experience you have will be useful in making comparisons between these two frameworks.

Finally, while this book is not exclusively focused on web applications, a good portion of it is dedicated to this topic. In fact, the final four chapters demonstrate how Spring can support the development your applications’ web layer. If you are a web application developer, you will find the last part of this book especially valuable.

Code conventions

There are many code example throughout this book. These examples will always appear in a fixed-width code font. If there is a part of example we want you to pay extra attention to, it will appear in a bolded code font. Any class name, method name, or XML fragment within the normal text of the book will appear in code font as well.

Many of Spring’s classes and packages have exceptionally long (but expressive) names. Because of this, line-continuation markers () may be included when necessary.

Not all code examples in this book will be complete. Often we only show a method or two from a class to focus on a particular topic.

Complete source code for the application found throughout the book can be downloaded from the publisher’s website at www.manning.com/walls3 or www.manning.com/SpringinAction.

About the author

Craig Walls is a software developer with more than 13 years’ experience and is the coauthor of XDoclet in Action (Manning, 2003). He’s a zealous promoter of the Spring Framework, speaking frequently at local user groups and conferences and writing about Spring on his blog. When he’s not slinging code, Craig spends as much time as he can with his wife, two daughters, six birds, four dogs, two cats, and an ever-fluctuating number of tropical fish. Craig lives in Denton, Texas.

Author Online

Purchase of Spring in Action includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/walls3 or www.manning.com/SpringinAction. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the book’s forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions, lest his interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint