Spring 2.5 Aspect-Oriented Programming by Massimiliano Dessì, is the first and unique book (332 pages) totally dedicated to Spring AOP, it was recently published by Packt Publishing.
Massimiliano Dessì works as Software Architect and Engineer for Sourcesense, who started developing JEE applications in 2000. In 2004 he discovered the Spring Framework 1.0, and since then he has been one of its most enthusiastic users.
This book is dedicated to developers that works every day on J2EE applications and they would like to know more about Aspect-Oriented Programming (AOP) and Spring AOP. I think that this book can be considered as a deep methodological documentation for Spring AOP. Every concept is explained with its own example and in more than one way, tipically in the following two ways:
- configuration way (XML)
- programmatic way (Java)
The way depends strongly on features you need to implement for your applications and it depends on your choices about your own software architecture. In the same way the AOP approach depends on how your application requires cross-cutting implementations and if your software factory woudl like to accept this philosophy.
The target audience of the book is developers who would like to start to implement for the first time AOP patterns or who would like to explore in a deeply way Spring AOP patterns. The necessary requirement to approach to this book is a basic knowledge about Spring Core and Inversion-Of-Control pattern (IoC).
For who doesn't know Spring Framework, Spring is a layered Java/J2EE application platform based on IoC pattern and it is divided in many sub-frameworks. Spring AOP is one of Spring sub-frameworks and on this book you can find all you need to know about how to use it for your implementations.
You can take a first look at the following titles of all the eight chapters provided in this book:
- Chapter 1: Understanding AOP Concepts
- Chapter 2: Spring AOP Components
- Chapter 3: Spring AOP Proxies
- Chapter 4: AspectJ Support
- Chapter 5: Design with AOP
- Chapter 6: Domain-Driven Design
- Chapter 7: Test and AOP
- Chapter 8: Develop with AOP Tools
Chapter 1: Understanding AOP Concepts
The first chapter is dedicated to a wide intriduction about all the main concepts that people who is approaching to AOP must know. All these components are described with their own definitions and their basic implementation examples.
There is an detailed description about crosscutting concerns implemented using Object-Oriented Programming (OOP) and using AOP. I have appreciated the exploration about code scattering and code tangling with examples.
I think in this way it could be more easy understand for eveyone:
- what AOP do for you and for your code quality (obviously only for all the code involved in using AOP)
- if AOP can help you in some modules of your application
The adoption of AOP usually is not full but partial within applications or legacy systems already developed, it may have been nice to have a section dedicated to this.
Chapter 2: Spring AOP Components
In this chapter all the Spring components dedicated to AOP are described and shown in a structured way with examples.
The most important AOP components described are: Aspect, Joinpoint, Advice and Poincut.
The other compontents described are Matchers and Advisors and we find here how to define the behaviour of your needed aspect: when and where the aspect action must be executed.
Chapter 3: Spring AOP Proxies
In this chapter has described how to implement proxies, starting from JDK proxy implementations (based on explicit use of the Reflection package).
Then we find a paragraph about how to implement proxies programmatically using Spring AOP with ProxyFactoryBean (using Interceptors).
But the most interesting way and I think the most used by developers (because it is adopted by many Enterprise products too) is to create proxies with Autoproxy definitions.
There are paragraphes dedicated to Autoproxy with AspectJ, annotation and XML Schema.
So I think that this chapter can be considered the real core of the book, there are very useful snippets that you can try on your application.
Chapter 4: AspectJ Support
In this chapter you can find all the features supported by Spring AOP dedicated to AspectJ, all the annotations and how to use this extension in a Spring context.
All the selection modes to inject aspects are described with different selection policies: method name, type of argument, type of return, declared exceptions, hierarchy and annotations.
Chapter 5: Design with AOP
In this chapter the main AOP design solutions are described as well. The main goals described for AOP adoption are the following: concurrency, transparent caching and security.
There is a complete example about how to implement all of these solutions with all the test classes too.
About the security solution we find the description of different definition types to implement the verification of authentication and authorization: using interceptors, using pointcuts or using annotations.
With all these possibilities developers can choose the best way for their application code and architecture: usually again using an XML configuration or a programmatic way.
Chapter 6: Domain-Driven Design
In this chapter we find a little and well done introduction to the Domain-Driven Design (DDD) explaining the different approach of this pattern focused on classes roles and responsability. The goal of DDD is based on create applications without big service classes but with many little classes to match all the domain.
Here we find a description for the main roles usually associated to classes that are managed by business logic to contribute on different operations (entity, value objects, factories, etc...).
Follow one of the big examples of the book to show an application implemented with DDD showing all the test classes too.
All these concepts allow developers to learn how to prepare their applications to IoC to create more debuggable and testable applications implementing easily Dependency Injection (DI).
Chapter 7: Tests and AOP
All this chapter is dedicated to show how to test your Spring application using AOP. We find a complete sample of a test suite with all the code commented.
For this chapter I confess that I would have preferred more methodological details rather than all this source code.
Chapter 8: Develop with AOP Tools
This final chapter is dedicated to show how to setup the working environment for Spring AOP, so I think it can be useful only for developers that never used Spring Framework.
So we find the installation instructions for the following products and frameworks: Spring and Spring IDE, Eclipse, AspectJ Development Tools, Apache Tomcat and PostgreSQL.
I have appreciated effort for having described all these procedures for different operating systems (Windows, Mac OS X and Linux).
In conclusion Spring 2.5 Aspect-Oriented Programming is a good and unique work and it is highly recommended for developers focused (or would like to focus) on Spring AOP!
If you would like to see all the details about chapters and paragraphes of this book, then you can visit the detailed table of contents.
You can download Chapter 5 - Design with AOP directly from Packt Publishing website for free: