Java Reference
In-Depth Information
has a children attribute of type List , so it's assigned to a list containing bart and
lisa .
I don't want to go through all the tests here, but there are a couple of features that should
be highlighted. For example, you can define beans at different scopes, as shown in the next
listing.
Listing 7.30. Defining beans at different scopes
void testScopes() {
def bb = new BeanBuilder()
bb.beans {
myBean(ScopeTest) { bean ->
bean.scope = "prototype"
}
myBean2(ScopeTest)
}
def ctx = bb.createApplicationContext()
def b1 = ctx.myBean
def b2 = ctx.myBean
assert b1 != b2
b1 = ctx.myBean2
b2 = ctx.myBean2
assertEquals b1, b2
}
By setting the scope attribute on myBean to prototype , retrieving the bean twice res-
ults in separate instances. The scope of myBean2 is singleton by default, so asking for it
twice results in two references to the same object.
You can also use tags from different Spring namespaces. Earlier in this chapter I created an
aspect using Groovy. The following listing shows a similar case using the BeanBuilder .
Listing 7.31. Defining an aspect using BeanBuilder
void testSpringAOPSupport() {
def bb = new BeanBuilder()
bb.beans {
xmlns aop:"http://www.springframework.org/schema/aop"
Search WWH ::




Custom Search