In this chapter, we go into more detail about the AOP features available in Spring. In particular, we look at the topic in a much more real-world light: we explore the framework services in Spring that allow for transparent application of AOP, we cover real-world usage of AOP in the context of the sample application, and we also discuss overcoming the limitations of Spring AOP using Spring/AspectJ integration. More specifically, this chapter covers the following:
Advanced use of pointcuts: This chapter finishes discussing pointcutting by looking at both ComposablePointcut and ControlFlowPointcut. This section also summarizes the whole pointcut discussion and looks at the appropriate techniques you should employ when you are using pointcuts in your application.
Introductions: Mentioned briefly in the previous chapter, introductions allow you to add interface implementations dynamically to any object on the fly using the familiar interceptor concept.
AOP framework services: We skipped over this topic completely in the previous chapter and focused solely on assembling AOP proxies and advice chains manually. However, in true Spring fashion, the framework fully supports configuring AOP transparently and declaratively. In this section, we look at how you can use the ProxyFactoryBean to inject declaratively defined AOP proxies into your application objects as collaborators, thus making your application completely unaware that it is working with advised objects. This section also looks at the autoproxying facilities Spring provides to ease the burden of configuring many different proxies.
Integrating AspectJ: AspectJ is a fully featured, statically compiled AOP implementation. The feature set of AspectJ is much greater than that of Spring AOP, but it is much more complicated to use than Spring. As mentioned in the previous chapter, AspectJ is a good solution when you find that Spring AOP lacks a feature you need. As of version 1.1 of Spring, you can take full advantage of Spring features when configuring your AspectJ aspects.
AOP in the sample application: In this section, we discuss how we solved some problems in the sample application using AOP. Specifically, we look at how we used Spring AOP to create an obscenity filter for the SpringBlog application that can be applied across as many methods as possible.
In order to run some of the examples in this chapter, you need to obtain AspectJ. You can download it from http://eclipse.org/aspectj. We used version 1.2 of AspectJ for the examples in this chapter.