Java Reference
In-Depth Information
fred(AdvisedPerson) {
name = "Fred"
age = 45
}
birthdayCardSenderAspect(BirthdayCardSender)
aop.config("proxy-target-class":true) {
aspect(id:"sendBirthdayCard",ref:"birthdayCardSenderAspect" ) {
after method:"onBirthday", pointcut:
"execution(void grails.spring.AdvisedPerson.birthday())
and this(person)"
}
}
}
def appCtx = bb.createApplicationContext()
def fred = appCtx.getBean("fred")
assertTrue (fred instanceof SpringProxy )
fred.birthday()
BirthdayCardSender birthDaySender = appCtx.getBean(
"birthdayCardSenderAspect")
assertEquals 1, birthDaySender.peopleSentCards.size()
assertEquals "Fred", birthDaySender.peopleSentCards[0].name
}
The aop namespace is declared using xmlns . In the builder that's interpreted as a (non-
existent) method call, whose interpretation is to make the namespace available under the
aop prefix. The fred bean is an instance of AdvisedPerson , whose definition is
@Component(value = "person")
class AdvisedPerson {
int age
String name
void birthday() {
++age
}
}
The birthdayCardSenderAspect is an instance of BirthdayCardSender ,
which is defined at the bottom of the file:
class BirthdayCardSender {
List peopleSentCards = []
Search WWH ::




Custom Search