Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
06b1f31c
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 搜索 >>
提交
06b1f31c
编写于
11月 19, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SynthesizedMergedAnnotationInvocationHandler does not pre-load values
Closes gh-24029
上级
4af60393
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
150 addition
and
223 deletion
+150
-223
spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
...otation/SynthesizedMergedAnnotationInvocationHandler.java
+0
-3
spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
...springframework/core/annotation/AnnotationUtilsTests.java
+18
-11
spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
...ringframework/core/annotation/MergedAnnotationsTests.java
+132
-209
未找到文件。
spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java
浏览文件 @
06b1f31c
...
...
@@ -61,9 +61,6 @@ final class SynthesizedMergedAnnotationInvocationHandler<A extends Annotation> i
this
.
annotation
=
annotation
;
this
.
type
=
type
;
this
.
attributes
=
AttributeMethods
.
forAnnotationType
(
type
);
for
(
int
i
=
0
;
i
<
this
.
attributes
.
size
();
i
++)
{
getAttributeValue
(
this
.
attributes
.
get
(
i
));
}
}
...
...
spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java
浏览文件 @
06b1f31c
...
...
@@ -28,6 +28,7 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.NoSuchElementException
;
import
java.util.Set
;
import
javax.annotation.Nonnull
;
...
...
@@ -46,7 +47,7 @@ import static java.util.Arrays.stream;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegal
Argument
Exception
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatIllegal
State
Exception
;
import
static
org
.
springframework
.
core
.
annotation
.
AnnotationUtils
.
VALUE
;
import
static
org
.
springframework
.
core
.
annotation
.
AnnotationUtils
.
findAnnotation
;
import
static
org
.
springframework
.
core
.
annotation
.
AnnotationUtils
.
findAnnotationDeclaringClass
;
...
...
@@ -685,7 +686,8 @@ class AnnotationUtilsTests {
assertThat
(
values
).
isEqualTo
(
expectedValuesJava
);
// Spring
Set
<
MyRepeatable
>
set
=
getDeclaredRepeatableAnnotations
(
MyRepeatableClass
.
class
,
MyRepeatable
.
class
,
MyRepeatableContainer
.
class
);
Set
<
MyRepeatable
>
set
=
getDeclaredRepeatableAnnotations
(
MyRepeatableClass
.
class
,
MyRepeatable
.
class
,
MyRepeatableContainer
.
class
);
assertThat
(
set
).
isNotNull
();
values
=
set
.
stream
().
map
(
MyRepeatable:
:
value
).
collect
(
toList
());
assertThat
(
values
).
isEqualTo
(
expectedValuesSpring
);
...
...
@@ -720,7 +722,8 @@ class AnnotationUtilsTests {
@Test
void
synthesizeAnnotationWithImplicitAliasesWithMissingDefaultValues
()
throws
Exception
{
Class
<?>
clazz
=
ImplicitAliasesWithMissingDefaultValuesContextConfigClass
.
class
;
Class
<
ImplicitAliasesWithMissingDefaultValuesContextConfig
>
annotationType
=
ImplicitAliasesWithMissingDefaultValuesContextConfig
.
class
;
Class
<
ImplicitAliasesWithMissingDefaultValuesContextConfig
>
annotationType
=
ImplicitAliasesWithMissingDefaultValuesContextConfig
.
class
;
ImplicitAliasesWithMissingDefaultValuesContextConfig
config
=
clazz
.
getAnnotation
(
annotationType
);
assertThat
(
config
).
isNotNull
();
...
...
@@ -735,7 +738,8 @@ class AnnotationUtilsTests {
@Test
void
synthesizeAnnotationWithImplicitAliasesWithDifferentDefaultValues
()
throws
Exception
{
Class
<?>
clazz
=
ImplicitAliasesWithDifferentDefaultValuesContextConfigClass
.
class
;
Class
<
ImplicitAliasesWithDifferentDefaultValuesContextConfig
>
annotationType
=
ImplicitAliasesWithDifferentDefaultValuesContextConfig
.
class
;
Class
<
ImplicitAliasesWithDifferentDefaultValuesContextConfig
>
annotationType
=
ImplicitAliasesWithDifferentDefaultValuesContextConfig
.
class
;
ImplicitAliasesWithDifferentDefaultValuesContextConfig
config
=
clazz
.
getAnnotation
(
annotationType
);
assertThat
(
config
).
isNotNull
();
assertThatExceptionOfType
(
AnnotationConfigurationException
.
class
).
isThrownBy
(()
->
...
...
@@ -749,7 +753,8 @@ class AnnotationUtilsTests {
@Test
void
synthesizeAnnotationWithImplicitAliasesWithDuplicateValues
()
throws
Exception
{
Class
<?>
clazz
=
ImplicitAliasesWithDuplicateValuesContextConfigClass
.
class
;
Class
<
ImplicitAliasesWithDuplicateValuesContextConfig
>
annotationType
=
ImplicitAliasesWithDuplicateValuesContextConfig
.
class
;
Class
<
ImplicitAliasesWithDuplicateValuesContextConfig
>
annotationType
=
ImplicitAliasesWithDuplicateValuesContextConfig
.
class
;
ImplicitAliasesWithDuplicateValuesContextConfig
config
=
clazz
.
getAnnotation
(
annotationType
);
assertThat
(
config
).
isNotNull
();
...
...
@@ -780,7 +785,8 @@ class AnnotationUtilsTests {
@Test
@SuppressWarnings
(
"unchecked"
)
void
synthesizeAnnotationFromMapWithNestedMap
()
throws
Exception
{
ComponentScanSingleFilter
componentScan
=
ComponentScanSingleFilterClass
.
class
.
getAnnotation
(
ComponentScanSingleFilter
.
class
);
ComponentScanSingleFilter
componentScan
=
ComponentScanSingleFilterClass
.
class
.
getAnnotation
(
ComponentScanSingleFilter
.
class
);
assertThat
(
componentScan
).
isNotNull
();
assertThat
(
componentScan
.
value
().
pattern
()).
as
(
"value from ComponentScan: "
).
isEqualTo
(
"*Foo"
);
...
...
@@ -827,7 +833,8 @@ class AnnotationUtilsTests {
filters
[
1
].
put
(
"pattern"
,
"newBar"
);
filters
[
1
].
put
(
"enigma"
,
42
);
ComponentScan
synthesizedComponentScan
=
synthesizeAnnotation
(
attributes
,
ComponentScan
.
class
,
ComponentScanClass
.
class
);
ComponentScan
synthesizedComponentScan
=
synthesizeAnnotation
(
attributes
,
ComponentScan
.
class
,
ComponentScanClass
.
class
);
assertThat
(
synthesizedComponentScan
).
isNotNull
();
assertThat
(
synthesizedComponentScan
).
isNotSameAs
(
componentScan
);
...
...
@@ -911,16 +918,16 @@ class AnnotationUtilsTests {
}
private
void
assertMissingTextAttribute
(
Map
<
String
,
Object
>
attributes
)
{
assertThat
IllegalArgumentException
(
).
isThrownBy
(()
->
synthesizeAnnotation
(
attributes
,
AnnotationWithoutDefaults
.
class
,
null
))
assertThat
ExceptionOfType
(
NoSuchElementException
.
class
).
isThrownBy
(()
->
synthesizeAnnotation
(
attributes
,
AnnotationWithoutDefaults
.
class
,
null
)
.
text
()
)
.
withMessageContaining
(
"No value found for attribute named 'text' in merged annotation"
);
}
@Test
void
synthesizeAnnotationFromMapWithAttributeOfIncorrectType
()
throws
Exception
{
Map
<
String
,
Object
>
map
=
Collections
.
singletonMap
(
VALUE
,
42L
);
assertThatIllegal
Argument
Exception
().
isThrownBy
(()
->
synthesizeAnnotation
(
map
,
Component
.
class
,
null
))
assertThatIllegal
State
Exception
().
isThrownBy
(()
->
synthesizeAnnotation
(
map
,
Component
.
class
,
null
)
.
value
()
)
.
withMessageContaining
(
"Attribute 'value' in annotation org.springframework.stereotype.Component "
+
"should be compatible with java.lang.String but a java.lang.Long value was returned"
);
}
...
...
spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java
浏览文件 @
06b1f31c
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录