Beginning Spring 2

One Minute Review

Positives
  • Covers all important aspects of Spring framework
  • Gives a good overview of the process of constructing an enterprise application using Spring
  • Illustrates the concepts with a comprehensive example of a timesheet management application
  • Its size is not intimidating to a beginner making the first steps in Spring development
  • Can be used by a manager who simply wants to understand what all the buzz is about
Negatives
  • May not be sufficient by itself to help someone actually build an enterprise Spring application

Buy it now

Ratings and Stats

ISBN:1590596854 Relevance:
4
Publisher:Apress Readability:
4
Author(s):Dave Minter Overall:
4
Bottom Line:For a beginner trying to ease himself into Java development with Spring, for a manager needing to understand Spring concepts or even for a more experienced developer needing a refresher of Spring concepts, this book will do nicely. It is well-structured, features a good breadth of topics covering all tiers of enterprise Java applications, uses a lot of examples to illustrate the presented concepts and slim enough to be read in its entirety while that new Spring project goes under way.

If you need a single book, however, which will carry you through most aspect of a Spring-based project, I would recommend Craig Walls's Spring in Action. While much thicker, it gives you more theoretical underpinnings, covers material in greater detail and features more engaging and humorous writing style.

Intent and Audience

Unlike a much weightier and much more detailed Spring in Action by Craig Walls, Beginning Spring 2 sets more modest goals - to introduce the reader to the process of designing and building enterprise application using Spring 2 framework. Where the former book's strength is in its completeness and the depth of coverage, the latter's advantage is in its accessibility. The intended audience for Beginning Spring 2 is a Java programmer with no prior exposure to Spring. The only other prerequisite the author, Dave Minter, mentions is working experience with XML. I feel that this approach works only to a certain degree. If your goal is to understand the ingredients of a enterprise application and how Spring ties them together, the book will provide you with the necessary knowledge. The issue I have with the superficial nature of the book is related to the nature of the Spring framework itself. Spring is mostly a glue that holds the application together. To create an application one needs to understand the underpinnings of enterprise development (persistence, transactionality, security, distribution, MVC, etc.) as well as such frameworks and APIs as JDBC, Hibernate, Servlets, JSP, etc. The book does provide brief explanations of each of the relevant concepts and illustrates their usage with an example or two. But those explanations and examples are not sufficient to introduce a complete novice to those concepts. To understand what Spring adds to the enterprise frameworks discussed in the book, I feel that the reader must have some experience with them or at least good understanding of their principles.

Chapter Highlights

Chapter 1. An Introduction to Spring.

The author starts off by giving his interpretation of terms defining the topic of the book explaining to the reader the notion of frameworks, the adjectives "lightweight" and "agile" as they apply to Spring framework, and the two foundation concepts of Spring, Dependency Injection and Aspect-Oriented Programming. The chapter also talks about features available in Spring for Web application development, as well as tools for Spring development such as Maven and Spring IDE Plug-in.

Chapter 2. Presenting the Sample

In this chapter Dave Minter gives the overview of the online timesheet application whose construction is illustrated by the examples throughout the book. He starts with the architectural discussion describing the standard three-tier architecture, followed by a simple specification and several use cases describing typical usage of the application. The remainder of the chapter is dedicated to the basics of Maven used to manage sample application build process.

Chapter 3. The Heart of Spring: Inversion of Control

The discussion of dependency injections starts with its rationale, its benefits and drawbacks, and situations where it is most useful (and those where it is not). The author presents two ways to use dependency injection in Spring - programmatic (since it is rarely used, I found it amusing that the author presented it first) and the more common way - through an XML descriptor. Seeing the verbosity of the programmatic approach made me realize the comparative elegance of XML descriptors (which, in turn look cumbersome compared to Spring 2.5 annotations, which are not covered in this book). Besides standard topics of property and constructor injection and auto-wiring, the chapter mentions usage of namespaces in configuration files. The chapter concludes with very brief discussions of BeanFactory and life-cycle events it makes available, application contexts and resource injection.

Chapter 4. Data Access

The chapters starts with the explanation of the Data Access Object pattern and Spring template classes used to implement DAOs. The two types of data access technologies the author chose to present are JDBC and Hibernate, covering the two ends of the spectrum based on their levels of abstraction. The sections dedicated to those technologies are sufficient to give the reader the flavor of the JDBC- and Hibernate-based data access implementation, but are inadequate as hands-on guides.

Chapter 5. The Service Layer, Transaction Management and AOP

The introduction of AOP makes this chapter the most dense one in the book. I am curious why the author decided to expend much more effort presenting AOP than, for example, Hibernate. While AOP is no doubt a very exiting and revolutionary technology, learning basics of ORM technologies would be more useful in a typical application. The firs part of the chapter is concerned with transactions, their basics, types of transaction managers and ways to configure them using annotations and XML descriptors. The remainder of the chapter, dedicated to Aspect-Oriented Programming, introduces both native Spring support of aspects as well as support for AspectJ annotations. The AOP examples the author presents deal with securing the timesheet application. To give the reader a more in-depth look at AOP constructs, the author complements the declarative approach of using AOP with Spring with a programmatic one by implementing pointcuts as Java classes.

Chapter 6. Web Applications

In the chapter dedicated to the presentation tier, Mr. Minter covers Spring MVC, its integration with Spring Web Flow and two view technologies that can be used in place of Java Server Pages, Velocity and FreeMarker. The Spring MVC section presents such basic concepts as Dispatchers, Controllers, Views and Resolvers and shows how they work together to implement the MVC pattern. The chapter only mentions SimpleFormController and only UrlBasedViewResolver. Validation and exception handling are briefly addressed. The chapter also touches upon the above-mentioned view technologies and Spring tag libraries.

Chapter 7. Security

This is the second section of the book (after the AOP discussion), where the author dedicates more than average amount of material to a single topic. The chapter starts with a brief overview of security in general and Spring (Acegi) Security framework in particular. The presentation of Spring Security frameworks covers two principal subjects - filters and providers. The section on filters covers the notion of filter chaining, and shows an example of filter configuration containing authentication processing, anonymous processing, security interceptor and exception translation filters. If filter configuration is concerned with what to do, providers determine how that processing is to be done. The provider section deals mostly with authentication, specifically through DAO authentication provider, mentioning other providers at the end. The chapter also discusses the mechanisms for applying security decisions programmatically through security JSP tags and security context object as well as the ways to apply security to the middle tier through Acegi annotations.

Chapter 8. Sending E-mail

This entire chapter is dedicated to using email in enterprise applications. The chapter introduces Spring API support for sending text and MIME messages (MailSender and JavaMailSender). Next the author covers the mechanism behind sending plain text messages, progressing to using Velocity for HTML-formatted messages and concluding with a section on attaching images and arbitrary files to HTML mail messages.

Chapter 9. Remoting

Having explained the need for remoting mechanism in the enterprise applications, the author dedicates the remainder of the chapter to the remoting protocols supported by Spring. The first protocol introduced is RMI. The section provides an example of the configuration of an RMI server and implementation of an RMI client in Spring. Next, the chapter moves to the HTTP-based remoting mechanisms represented by Spring HTTP invoker, Hessian and Burlap. The sections on Hessian and Burlap explain how to work around the problem of using Hibernate proxy objects (supporting lazy loading of entities) across the wire. The last section of the chapter dealing with the SOAP protocol presents the examples of JAX-RPC server and client implemented using Apache Axis.

Chapter 10. Testing

The chapter starts with a discourse on the evolution of testing and advantages of automated tests. Following the introduction of concepts of test-driven development, and mock objects, the chapter proceeds with examples of writing tests for most of the functionality explored in the preceding chapters. That covers tests for data access objects and their realizations for JDBC and Hibernate, tests for email components, tests for service and presentation layers. The chapter concludes with discussions of integration testing, web testing and regression testing.

Appendix

The book concludes with a useful appendix describing the installation and usage of Spring IDE Plug-in for Eclipse whose goal is to automate common Spring configuration tasks.

Relevance of Material

The Beginning Spring 2 book covers a significant number of technologies, which are put together under a single umbrella by the genius of Spring framework creators to enable their seamless integration in creation of enterprise Java applications. Besides the technologies already mentioned, the book deals with Maven, dependency injection, aspect-oriented programming, JavaMail API, Acegi (Spring) Security, Velocity and FreeMarker, RMI and other remoting mechanisms, SOAP and JUnit. A Spring developer is likely to encounter many, if not most, of these concepts and technologies in practice. This book will make its reader understand the role those disparate technologies play in creation of enterprise application and, importantly, the way Spring makes their integration not only possible but simple.

I like the logical organization of the book. It covers the Spring concepts in the order matching that of creation of an enterprise application. The chapter presenting the sample application gives a simple architectural overview of the system and maps the application layers to the book chapters. Following good software practices, it even creates a simplified specification of the timesheet management application in the form of use cases. The individual chapters themselves, as I already mentioned, illustrate the concepts well, but do not, in my opinion, contain enough information for a reader to develop a Spring application. The reader unfamiliar with Hibernate, for example, would have to use a separate information source for that framework in addition to Beginning Spring 2. Similarly, if one wanted to go beyond a simple form controller using Spring MVC, this book would fall short. The chapter on dependency injection, an idea that started Spring, covers the basic notions, but does not go into more advanced topics such as bean scoping or abstracting base bean types.

Resources

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)