Java Reference
In-Depth Information
void onBirthday(AdvisedPerson person) {
peopleSentCards << person
}
}
Using the
config
element from the
aop
namespace, the builder declares an aspect called
sendBirthdayCard
that references the aspect. After any execution of the birthday
method in an advised person, the aspect's
onBirthday
method is executed, which adds
the person to the
peopleSentCards
collection. The test then verifies that the aspect did
in fact run.
Other tests illustrate other capabilities in
BeanBuilder
. For example, if the property
you're trying to set requires a hyphen, you put the property in quotes. Some tests show ex-
amples like
aop.'scoped-proxy'()
or
jee.'jndi-lookup'(id:"foo", 'jndi-name':"bar")
See the test file for a wide range of examples. The bottom line is that anything you can do
in a regular Spring bean configuration file, you can do with the Grails
BeanBuilder
.
Lessons learned (Spring with Groovy)
1
. Spring manages POGOs the same way it manages POJOs, so beans can be imple-
mented in Groovy as easily as in Java.
2
. Closure coercion eliminates the need for anonymous inner classes.
3
. By adding a single JAR file, Spock tests work inside the Spring test context.
4
. Refreshable beans allow you to modify the system without restarting it.
5
. Inline scripted beans are embedded in configuration files.
6
. The Grails
BeanBuilder
gives yet another way to configure Spring.