img
Note When you refer to Spring's reference manual, you will also see another mechanism called automatic
proxying. Basically, it provides a few ways for you to define and apply the advice to a number of Spring beans
within the ApplicationContext. For example, the BeanNameAutoProxyCreator class allows you to advise a
number of Spring beans by the name, while the DefaultAdvisorAutoProxyCreator class allows you to apply an
advisor to the beans within the ApplicationContext with the pointcut logic defined in the Advisor
implementation class. However, both mechanisms can now be easily handled by the powerful pointcut expression
support in both the aop namespace and @AspectJ-style annotations. So, we decided to skip the discussion of the
automatic proxying here, but if you are interested, you can refer to Spring's reference manual for details.
AspectJ Integration
AOP provides a powerful solution to many of the common problems that arise with OOP-based
applications. When using Spring AOP, you can take advantage of a select subset of AOP functionality
that, in most cases, allows you to solve problems you encounter in your application. However, in some
cases, you may want to use some AOP features that are outside the scope of Spring AOP.
From the joinpoint perspective, Spring AOP only supports pointcuts matching on the execution of
public nonstatic methods. However, in some cases, you may need to apply advice to protected/private
methods, during object construction or field access, and so on.
In those cases, you need to look at an AOP implementation with a fuller feature set. Our preference,
in this case, is to use AspectJ, and because you can now configure AspectJ aspects using Spring, AspectJ
forms the perfect complement to Spring AOP.
About AspectJ
AspectJ is a fully featured AOP implementation that uses a weaving process (either compile-time or
load- time weaving) to introduce aspects into your code. In AspectJ, aspects and pointcuts are built
using a Java-like syntax, which reduces the learning curve for Java developers. We are not going to
spend too much time looking at AspectJ and how it works because that is outside the scope of this
topic. Instead, we present some simple AspectJ examples and show you how to configure them using
Spring. For more information on AspectJ, you should definitely read AspectJ in Action: Enterprise AOP
with Spring Applications, 2nd Edition, by Ramnivas Laddad (Manning, 2010).
Note We are not going to cover how to weave AspectJ aspects into your application. Refer to the AspectJ
documentation for details on how to achieve this. Alternatively, Eclipse users can download the Eclipse AspectJ
Development Tools (AJDT) and take advantage of full IDE integration and autocompilation. AJDT was also bundled
with SpringSource Tool Suite (STS), so you don't need to download it separately when using STS.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home