Welcome to the first edition of Pro Spring MVC with Web Flow; the first Pro Spring book focused entirely on web development using the Spring Framework 3.1 ecosystem.
This book will teach you everything you need to know in order to get started building enterprise-quality web applications using version 3.1 of the Spring Framework. Topics include but are not limited to:
After reading this book you will be familiar with the Spring MVC toolkit and capable of building your own web application from scratch or providing a new web interface to an existing application.
All too often trivial examples are used to demonstrate the power of a framework; it is only when you start using the framework in real situations that its limitations appear. The intention of this book is to show how Spring MVC answers those hard questions (as well as the easy questions!) that web developers are faced with, like managing state in non-trivial multi-page use cases, for example, or providing multiple views of the same resource for different consumers.
And because the real-world problems this book tackles are hard, sometimes the answers Spring MVC provides are not as easy as one would like. This book will not shy away from highlighting those issues or providing pragmatic advice on how to do the right thing.
This book is for those who are familiar with Spring and want to gain an in-depth understanding of Spring MVC. While it is primarily aimed at those new to Spring MVC, there is information here that will take even expert MVCers by surprise!
The typical reader will be a web developer who has some understanding of the core Spring framework (after reading Pro Spring for example) and wants to investigate Spring MVC in more detail.
If you are unfamiliar with Spring, then by all means continue reading; particularly Chapter 2. However if you find that is insufficient then you might find the Spring Reference Guide1 or Pro Spring 3 (Apress, 2012).
The original Spring book, Expert One-on-One J2EE Design and Development (Wrox, 2002)2, by Rod Johnson (the “father“ of the Spring framework), is fairly old now but still relevant and full of wisdom.
This book will take the reader through the thought process of designing, implementing, and deploying a Java web application. The order of the chapters follows the chronological order defined by the development lifecycle. During these chapters we use a sample application to illustrate the topics discussed in the chapter.
Each chapter will address a real-world problem by introducing a new concept or capability which is then used to upgrade the sample application.
Note There is a never-ending dilemma that authors face: should we show the answers first and then the questions, or show the questions and then the answers? The first approach risks overloading the reader, while the second approach can be frustrating and slow for those already familiar with the subject matter. The authors believel that the pace of this book is sufficient for those unfamiliar with Spring MVC; more experienced readers may want to skip certain chapters. For example, if you already have a development environment configured and are familiar with Spring then you can skim Chapter 1 to get hold of the sample application and then jump straight to Chapter 3.
While the example cannot be a true enterprise application (because we need to keep this book under 10K pages ;)), it is realistic enough to highlight the typical design challenges that are faced in real-world projects.
The example in question is the site for a web-enabled bookstore. It offers users the following capabilities:
__________
Throughout the rest of this book, each chapter adds a new aspect to the sample application. The simplest way of capturing this in the example was to have a new project for each chapter.
We need to explain a little about the coding and referencing style used throughout the book. You’ll find that some of the code listings are complete and can be taken directly from the book to the development environment. In others we omit some imports or methods that are mentioned in earlier listings; we’ve marked those with // Imports omitted
or // Methods omitted.
Most include a reference to the code listing in which the methods or imports can be found. This approach was needed for readability, as some code listings contain only a few new lines and others would span multiple pages.
Another thing to mention is that we did not include the fully qualified package names for common classes like java.lang.String
or java.util.HashMap
(most of the java.util
packages aren’t included), as a Java developer in general knows where to find those classes. Also, we only mention the fully qualified classname on the first significant reference (after the main heading); for example, the package first identified as org.springframework.web.servlet.DispatcherServlet
will in subsequent references be called simply DispatcherServlet.
This is again for readability, but we also feel the need to show you the location of the class and believe this was an acceptable approach.
The book consists of a series of chapters, each explaining a part of the framework or how to use a certain technology. The first four chapters are quite theoretical and are used to explain some of the more general concepts and how they apply or work within Spring MVC (the same goes for the start of the Spring Web Flow part of the book; Chapter 10 is also more or less theoretical).
After that introduction to the concepts behind Spring MVC, the remaining chapters follow a more practical and hands-on approach as we start to develop an application.
The chapters are:
DispatcherServlet.
ViewResolver
infrastructure and start to see the power of the MVC architecture shine through when you re-use the same infrastructure to provide different renditions of the same model.So before going any further let's take the first peek at Spring MVC and where it fits into the existing Spring ecosystem.
The first piece of good news is that Spring MVC is Spring. You configure Spring MVC using the existing powerful Spring container. Beans defined in Spring MVC are just like any other beans.
The following image from http://static.springsource.org/spring/docs/3.1.0.M2/spring-framework-reference/html/overview.html
is very helpful:
As you can see— Spring MVC is powered by the rest of Spring!
Now that you have an idea about the style and purpose of this book let's waste no more time in getting you set up with a development environment. We’ll see you in Chapter 1.
Marten Deinum can be contacted at [email protected]
for queries and suggestions for this book. His blog can be found at http://mdeinum.wordpress.com.
Feel free to contact him if you have found a mistake, want to ask a question, or want to discuss anything else related to the book.
Koen Serneels can be contacted at [email protected]
for anything related to this book. If you have suggestions, remarks, or questions, or have found something to be inaccurate, feel free to drop him a message. His blog can be found at http://www.error.be.