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)

CGLIB proxy


In the beginning, the use of the CGLIB library was introduced in Spring 1.1 because JDK 1.3 proxies weren't really efficient. With versions 1.4 and following, they have been improved. However, even with JDK 1.5, CGLIB proxies are still three times faster.

Despite all this, we have to notice that JDK proxies need an interface to do their job, and only the methods declared in the interface can be used by the proxy. But this is not always possible, particularly when the code we deal with is written by others.

In this case, it's better to use CGLIB proxies that don't require the presence of interfaces to implement. CGLIB proxies generate the bytecode for the new class on the fly for each proxy, reusing in those cases that were already created. This allows some optimizations.

But we have to be clear that to use CGLIB proxies, we need to have the CGLIB JAR. Whereas with JDK, any JAR is required. Moreover, if we deal with final methods, we cannot do the override, and so we can apply...