Java Reference
In-Depth Information
Dierk Koenig, lead author of Groovy in Action (Manning, 2007), calls this pattern “keyhole
surgery.” It's used as a minimally invasive procedure when you don't know what you're
going to find when you go in. [ 9 ]
9 Check out Dierk's presentation “Seven Groovy Usage Patterns for Java Developers” on www.slideshare.net for
more details.
Before discussing the other Spring capability restricted to beans from dynamic languages,
namely inline scripted beans, let me introduce another idea. One of the great features of
Spring is that it provides a convenient infrastructure for aspect-oriented programming. I
want to discuss what that means and how to use Groovy to implement an aspect.
7.3. Spring AOP with Groovy beans
Many of Spring's capabilities are implemented using aspect-oriented programming (AOP).
Spring provides the infrastructure for developing aspects. The interesting part is that as-
pects can be written as easily in Groovy as in Java.
AOPisabigsubject,butIcansummarize afewofthekeyfeatureshere. [ 10 ] Aspectsarede-
signed to handle crosscutting concerns , which are features that apply to many different loc-
ations. Examples of crosscutting concerns include logging, security, and transactions. Each
of them needs to be applied at multiple locations in a system, which results in considerable
duplication, as well as tangling of different kinds of functionality in the same feature.
10 A complete discussion of AOP can be found in AspectJ in Action , 2 nd edition (Manning, 2009), by Ramnivas
Laddad, www.mannin10g.com/laddad2/ .
Crosscutting concerns are written as methods, known as advice . The next issue is where to
apply the advice. The generic term for all available locations where advice can be applied
is joinpoints . The set of selected joinpoints for a given aspect is known as a pointcut . The
combination of an advice and a pointcut is what defines an aspect .
The sample application for this section and the next is shown in figure 7.4 .
 
 
Search WWH ::




Custom Search