Java Reference
In-Depth Information
import org.aspectj.lang.JoinPoint
import java.util.logging.Logger
class GroovyAspect {
Logger log = Logger.getLogger(GroovyAspect.getClass().getName())
def audit(JoinPoint jp) {
log.info "${jp.signature.name} on ${jp.target.class.name}"
}
}
]]>
</lang:inline-script>
</lang:groovy>
<aop:config>
<aop:aspect ref= "aspectScript" >
<aop:before method= "audit" pointcut= "execution(* *.*(*))" />
</aop:aspect>
</aop:config>
The <inline-script> tagwrapsthesourcecodefortheGroovybean.Itooktheadded
step of wrapping the code in a CDATA section, so the XML parser will leave the Groovy
source alone when validating the XML.
Rather than use annotations, this time the code is written as though it was any other bean.
As a result I had to add the <config> element as well. As usual, an aspect is a combin-
ation of a pointcut and an advice. In this case the pointcut is contained in the <before>
element, but this time it applies to every one-argument method in the system. The advice is
the audit method inthe aspectScript bean, which just prints the name ofthe method
being invoked and the name of the object containing it.
The resulting output adds more lines to the console:
INFO: setOne on mjg.POJO
INFO: setTwo on mjg.POJO
INFO: setThree on mjg.POJO
The original motivation for inline scripted beans was that you could do as much processing
as you liked in the script before releasing the bean. [ 13 ] Now that Spring has moved to ver-
sion 3.x, however, there are additional options for configuring beans.
13 As I say, it's a reach. The Spring docs suggest that this is a good opportunity for scripted validators, but I don't
see it.
 
Search WWH ::




Custom Search