Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
b0acb588
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b0acb588
编写于
8月 28, 2012
作者:
C
Chris Beams
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #125 from jeffbrown/beanbuilder
GRAILS-4995 - Improve the handling of List and Map ctor args
上级
c463fd02
a0b3da71
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
101 addition
and
69 deletion
+101
-69
spring-lang-groovy/src/main/java/org/springframework/context/groovy/GroovyBeanDefinitionReader.java
...gframework/context/groovy/GroovyBeanDefinitionReader.java
+7
-0
spring-lang-groovy/src/test/groovy/org/springframework/context/groovy/GroovyBeanDefinitionReaderTests.groovy
...ork/context/groovy/GroovyBeanDefinitionReaderTests.groovy
+94
-69
未找到文件。
spring-lang-groovy/src/main/java/org/springframework/context/groovy/GroovyBeanDefinitionReader.java
浏览文件 @
b0acb588
...
...
@@ -714,6 +714,13 @@ public class GroovyBeanDefinitionReader extends GroovyObjectSupport {
protected
List
resolveConstructorArguments
(
Object
[]
args
,
int
start
,
int
end
)
{
Object
[]
constructorArgs
=
subarray
(
args
,
start
,
end
);
filterGStringReferences
(
constructorArgs
);
for
(
int
i
=
0
;
i
<
constructorArgs
.
length
;
i
++)
{
if
(
constructorArgs
[
i
]
instanceof
List
)
{
constructorArgs
[
i
]
=
manageListIfNecessary
(
constructorArgs
[
i
]);
}
else
if
(
constructorArgs
[
i
]
instanceof
Map
){
constructorArgs
[
i
]
=
manageMapIfNecessary
(
constructorArgs
[
i
]);
}
}
List
constructorArgsList
=
Arrays
.
asList
(
constructorArgs
);
return
constructorArgsList
;
}
...
...
spring-lang-groovy/src/test/groovy/org/springframework/context/groovy/GroovyBeanDefinitionReaderTests.groovy
浏览文件 @
b0acb588
...
...
@@ -133,69 +133,61 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
void
testUseTwoSpringNamespaces
()
{
def
beanReader
=
new
GroovyBeanDefinitionReader
()
SimpleNamingContextBuilder
builder
=
new
SimpleNamingContextBuilder
()
try
{
builder
.
bind
(
"bar"
,
"success"
)
builder
.
activate
()
TestScope
scope
=
new
TestScope
()
GenericApplicationContext
appCtx
=
beanReader
.
getSpringConfig
().
getUnrefreshedApplicationContext
()
appCtx
.
getBeanFactory
().
registerScope
(
"test"
,
scope
)
beanReader
.
beans
{
xmlns
aop:
"http://www.springframework.org/schema/aop"
xmlns
jee:
"http://www.springframework.org/schema/jee"
scopedList
(
ArrayList
)
{
bean
->
bean
.
scope
=
"test"
aop
.
'scoped-proxy'
()
}
jee
.
'jndi-lookup'
(
id:
"foo"
,
'jndi-name'
:
"bar"
)
TestScope
scope
=
new
TestScope
()
GenericApplicationContext
appCtx
=
beanReader
.
getSpringConfig
().
getUnrefreshedApplicationContext
()
appCtx
.
getBeanFactory
().
registerScope
(
"test"
,
scope
)
beanReader
.
beans
{
xmlns
aop:
"http://www.springframework.org/schema/aop"
xmlns
util:
"http://www.springframework.org/schema/util"
scopedList
(
ArrayList
)
{
bean
->
bean
.
scope
=
"test"
aop
.
'scoped-proxy'
()
}
util
.
list
(
id:
'foo'
)
{
value
'one'
value
'two'
}
}
appCtx
=
beanReader
.
createApplicationContext
()
assertEquals
"success"
,
appCtx
.
getBean
(
"foo"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
appCtx
=
beanReader
.
createApplicationContext
()
// should only be true because bean not initialized until proxy called
assertEquals
2
,
scope
.
instanceCount
assert
[
'one'
,
'two'
]
==
appCtx
.
getBean
(
"foo"
)
beanReader
=
new
GroovyBeanDefinitionReader
()
assertNotNull
appCtx
.
getBean
(
"scopedList"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
appCtx
=
beanReader
.
getSpringConfig
().
getUnrefreshedApplicationContext
()
appCtx
.
getBeanFactory
().
registerScope
(
"test"
,
scope
)
beanReader
.
beans
{
xmlns
aop:
"http://www.springframework.org/schema/aop"
,
jee:
"http://www.springframework.org/schema/jee"
scopedList
(
ArrayList
)
{
bean
->
bean
.
scope
=
"test"
aop
.
'scoped-proxy'
()
}
// should only be true because bean not initialized until proxy called
assertEquals
2
,
scope
.
instanceCount
jee
.
'jndi-lookup'
(
id:
"foo"
,
'jndi-name'
:
"bar"
)
beanReader
=
new
GroovyBeanDefinitionReader
(
)
appCtx
=
beanReader
.
getSpringConfig
().
getUnrefreshedApplicationContext
()
appCtx
.
getBeanFactory
().
registerScope
(
"test"
,
scope
)
beanReader
.
beans
{
xmlns
aop:
"http://www.springframework.org/schema/aop"
,
util:
"http://www.springframework.org/schema/util"
scopedList
(
ArrayList
)
{
bean
->
bean
.
scope
=
"test"
aop
.
'scoped-proxy'
()
}
appCtx
=
beanReader
.
createApplicationContext
()
assertEquals
"success"
,
appCtx
.
getBean
(
"foo"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
// should only be true because bean not initialized until proxy called
assertEquals
4
,
scope
.
instanceCount
util
.
list
(
id:
'foo'
)
{
value
'one'
value
'two'
}
}
appCtx
=
beanReader
.
createApplicationContext
()
assert
[
'one'
,
'two'
]
==
appCtx
.
getBean
(
"foo"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
)
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
assertNotNull
appCtx
.
getBean
(
"scopedList"
).
size
()
}
finally
{
builder
.
deactivate
()
}
// should only be true because bean not initialized until proxy called
assertEquals
4
,
scope
.
instanceCount
}
void
testSpringAOPSupport
()
{
...
...
@@ -262,24 +254,17 @@ class GroovyBeanDefinitionReaderTests extends GroovyTestCase {
void
testSpringNamespaceBean
()
{
def
beanReader
=
new
GroovyBeanDefinitionReader
()
SimpleNamingContextBuilder
builder
=
new
SimpleNamingContextBuilder
()
try
{
builder
.
bind
(
"bar"
,
"success"
)
builder
.
activate
()
beanReader
.
beans
{
xmlns
jee:
"http://www.springframework.org/schema/jee"
jee
.
'jndi-lookup'
(
id:
"foo"
,
'jndi-name'
:
"bar"
)
beanReader
.
beans
{
xmlns
util:
'http://www.springframework.org/schema/util'
util
.
list
(
id:
'foo'
)
{
value
'one'
value
'two'
}
ApplicationContext
appCtx
=
beanReader
.
createApplicationContext
()
assertEquals
"success"
,
appCtx
.
getBean
(
"foo"
)
}
finally
{
builder
.
deactivate
()
}
def
ctx
=
beanReader
.
createApplicationContext
()
assert
[
'one'
,
'two'
]
==
ctx
.
getBean
(
'foo'
)
}
void
testNamedArgumentConstructor
()
{
...
...
@@ -772,9 +757,7 @@ beanReader.createApplicationContext()
assertEquals
"Fred"
,
appCtx
.
getBean
(
"personA"
).
name
}
// test for GRAILS-4995
void
testListOfBeansAsConstructorArg
()
{
if
(
notYetImplemented
())
return
def
beanReader
=
new
GroovyBeanDefinitionReader
()
beanReader
.
beans
{
...
...
@@ -790,6 +773,34 @@ beanReader.createApplicationContext()
assert
ctx
.
containsBean
(
'someotherbean2'
)
assert
ctx
.
containsBean
(
'somebean'
)
}
void
testBeanWithListAndMapConstructor
()
{
def
beanReader
=
new
GroovyBeanDefinitionReader
()
beanReader
.
beans
{
bart
(
Bean1
)
{
person
=
"bart"
age
=
11
}
lisa
(
Bean1
)
{
person
=
"lisa"
age
=
9
}
beanWithList
(
Bean5
,
[
bart
,
lisa
])
// test runtime references both as ref() and as plain name
beanWithMap
(
Bean6
,
[
bart:
bart
,
lisa:
ref
(
'lisa'
)])
}
def
ctx
=
beanReader
.
createApplicationContext
()
def
beanWithList
=
ctx
.
getBean
(
"beanWithList"
)
assertEquals
2
,
beanWithList
.
people
.
size
()
assertEquals
"bart"
,
beanWithList
.
people
[
0
].
person
def
beanWithMap
=
ctx
.
getBean
(
"beanWithMap"
)
assertEquals
9
,
beanWithMap
.
peopleByName
.
lisa
.
age
assertEquals
"bart"
,
beanWithMap
.
peopleByName
.
bart
.
person
}
void
testAnonymousInnerBeanViaBeanMethod
()
{
def
beanReader
=
new
GroovyBeanDefinitionReader
()
...
...
@@ -903,6 +914,20 @@ class Bean4 {
}
String
person
}
// bean with List-valued constructor arg
class
Bean5
{
Bean5
(
List
<
Bean1
>
people
)
{
this
.
people
=
people
}
List
<
Bean1
>
people
}
// bean with Map-valued constructor arg
class
Bean6
{
Bean6
(
Map
<
String
,
Bean1
>
peopleByName
)
{
this
.
peopleByName
=
peopleByName
}
Map
<
String
,
Bean1
>
peopleByName
}
// a factory bean
class
Bean1Factory
{
Bean1
newInstance
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录