Topic 7
■■■
More Spring AOP and Annotations
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 three
ways (the ProxyFactoryBean class, the aop namespace, and @AspectJ-style
annotations) 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.
Integrating AspectJ: AspectJ is a fully featured AOP implementation. The main
·
difference between AspectJ and Spring AOP is that AspectJ applies advice to target
objects via weaving (either compile-time or load-time weaving), while as
discussed in the previous chapter, Spring AOP is based on a proxy. The feature set
of AspectJ is much greater than that of Spring AOP, but it is much more
complicated to use than Spring. AspectJ is a good solution when you find that
Spring AOP lacks a feature you need. Starting from version 2.0, you can take full
advantage of Spring features when configuring your AspectJ aspects.
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.6.11 of AspectJ for the examples in this chapter. You can
also add the Maven dependencies in Table 7-1 into your STS project.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home