img
.
you are using the CGLIB proxy. For methods on the Advised interface, you will notice that they are also
faster on the CGLIB proxy. The reason for this is that Advised methods are handled early on in the
intercept() method so they avoid much of the logic that is required for other methods.
Which Proxy to Use?
Deciding which proxy to use is typically an easy decision. The CGLIB proxy can proxy both classes and
interfaces, whereas the JDK proxy can proxy only interfaces. In terms of performance, there is no
significant difference between JDK and CGLIB standard mode (at least in running both advised and
unadvised methods), unless you use CGLIB in frozen mode, in which case the advice chain can't be
changed and CGLIB performs further optimization when in frozen mode. When proxying a class, the
CGLIB proxy is the default choice because it is the only proxy capable of generating a proxy of a class. To
use the CGLIB proxy when proxying an interface, you must set the value of the optimize flag in the
ProxyFactory to true using the setOptimize() method.
Note Besides CGLIB, there is another bytecode manipulation library called Javassist, which is being used by
some other popular projects (e.g., Hibernate). Some developers prefer Javassist over CGLIB and have raised a
JIRA issue (http://jira.springsource.org/browse/SPR-5654) requesting the migration of the Spring AOP
proxy from CGLIB to Javassist. The Spring development team is considering it during the Spring 3.2 timeline.
There also exists an intermediate solution provided by the community. For those who interested in details about
using Javassist with Spring AOP, please refer to the JIRA issue for details.
Summary
In this chapter, we introduced the core concepts of AOP and then looked at how these concepts translate
into the Spring AOP implementation. We discussed the features that are and are not implemented in
Spring AOP, and we pointed to AspectJ as an AOP solution for those features that Spring does not
implement. We spent some time explaining the details of the advice types available in Spring, and you
saw examples of the four types in action. We also looked at how you limit the methods to which an
advice applies using pointcuts. In particular, we looked at the six basic pointcut implementations
available with Spring. Finally, we covered the details of how the AOP proxies are constructed, the
different options, and what makes them different. We concluded the discussion of proxies with a
comparison of the performance between three different proxy types and highlighted some major
differences and restrictions for choosing between a JDK vs. CGLIB proxy.
In Chapter 7, we will complete our discussion of the pointcuts available in Spring by looking at
ComposablePointcut and ControlFlowPointcut in detail. We will spend some time looking at how you
utilize Spring's AspectJ integration to extend the AOP feature set available to your application. We will
also look at how AOP is supported by Spring Framework services, which means you can define and
configure advice declaratively rather than programmatically.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home