Book Image

Spring 2.5 Aspect Oriented Programming

Book Image

Spring 2.5 Aspect Oriented Programming

Overview of this book

Developing powerful web applications with clean, manageable code makes the maintenance process much easier. Aspect-Oriented Programming (AOP) is the easiest and quickest way to achieve such results. Spring is the only Java framework to offer AOP features. The combined power of Spring and AOP gives a powerful and flexible platform to develop and maintain feature-rich web applications quickly. This book will help you to write clean, manageable code for your Java applications quickly, utilizing the combined power of Spring and AOP. You will master the concepts of AOP by developing several real-life AOP-based applications with the Spring Framework, implementing the basic components of Spring AOP: Advice, Joinpoint, Pointcut, and Advisor. This book will teach you everything you need to know to use AOP with Spring. It starts by explaining the AOP features of Spring and then moves ahead with configuring Spring AOP and using its core classes, with lot of examples. It moves on to explain the AspectJ support in Spring. Then you will develop a three-layered example web application designed with Domain-Driven Design (DDD) and built with Test-Driven Development methodology using the full potential of AOP for security, concurrency, caching, and transactions.
Table of Contents (13 chapters)

Transparent caching with AOP


Often, the objects that compose applications perform the same operations with the same arguments and obtain the same results. Sometimes, these operations are costly in terms of CPU usage, or may be there is a lot of I/O going on while executing those operations.

To get better results in terms of speed and resources used, it's suggested to use a cache. We can store in it the results corresponding to the methods' invocations as key-value pairs: method and arguments as key and return object as value.

Once you decide to use a cache you're just halfway. In fact, you must decide which part of the application is going to use the cache. Let's think about a web application backed by a database. Such a web application usually involves Data Access Objects (DAOs), which access the relational database. Such objects are usually a bottleneck in the application as there is a lot of I/O going on. In other words, a cache can be used there.

The cache can also be used by the business...