Chapter 4. Spring and AOP

Aspect-Oriented Programming (AOP) is an important technology, well-suited to solving many common problems. Spring offers AOP features to complement its IoC features and ensure that enterprise service code does not pollute your application objects.

In keeping with Spring's layered architecture, Spring's AOP features are separate from the core IoC container. You are not forced to use AOP with Spring. However, most users choose to do so, if only to leverage valuable out-of-the-box services provided by Spring, which are delivered using AOP.

Spring takes a pragmatic approach to AOP. You can use as little AOP as you want, or integrate with AspectJ to harness the power of AOP extensions to the Java language. While learning how to exploit the full power of AOP is likely to take the industry years, Spring enables incremental adoption of AOP without the risk of dragging projects to the bleeding edge. We recommend that you take the time to understand the basic concepts of this important technology, which can help you solve practical problems today.

Goals

Enterprise applications often face crosscutting concerns—concerns that might potentially affect code in many objects. Consider the following requirements:

  • Every operation on the AccountManager interface should be performed within a transaction.

  • The return values of certain expensive methods should be cached for a specified period of time.

  • Whenever an instance field is modified in a domain object, the object should be marked ...

Get Professional Java™ Development with the Spring Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.