Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
22a8a668
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,发现更多精彩内容 >>
提交
22a8a668
编写于
3月 30, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AnnotationTypeFilter assumes no custom annotations on common Java types
Issue: SPR-16667
上级
78681c63
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
13 deletion
+18
-13
spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java
...pringframework/core/type/filter/AnnotationTypeFilter.java
+8
-2
spring-core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java
.../springframework/core/type/AnnotationTypeFilterTests.java
+10
-11
未找到文件。
spring-core/src/main/java/org/springframework/core/type/filter/AnnotationTypeFilter.java
浏览文件 @
22a8a668
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
8
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -71,7 +71,9 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
* @param considerMetaAnnotations whether to also match on meta-annotations
* @param considerInterfaces whether to also match interfaces
*/
public
AnnotationTypeFilter
(
Class
<?
extends
Annotation
>
annotationType
,
boolean
considerMetaAnnotations
,
boolean
considerInterfaces
)
{
public
AnnotationTypeFilter
(
Class
<?
extends
Annotation
>
annotationType
,
boolean
considerMetaAnnotations
,
boolean
considerInterfaces
)
{
super
(
annotationType
.
isAnnotationPresent
(
Inherited
.
class
),
considerInterfaces
);
this
.
annotationType
=
annotationType
;
this
.
considerMetaAnnotations
=
considerMetaAnnotations
;
...
...
@@ -111,6 +113,10 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter
return
false
;
}
else
if
(
typeName
.
startsWith
(
"java"
))
{
if
(!
this
.
annotationType
.
getName
().
startsWith
(
"java"
))
{
// Standard Java classes don't have non-standard annotations on them.
return
false
;
}
try
{
Class
<?>
clazz
=
ClassUtils
.
forName
(
typeName
,
getClass
().
getClassLoader
());
return
((
this
.
considerMetaAnnotations
?
AnnotationUtils
.
getAnnotation
(
clazz
,
this
.
annotationType
)
:
...
...
spring-core/src/test/java/org/springframework/core/type/AnnotationTypeFilterTests.java
浏览文件 @
22a8a668
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
8
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -49,7 +49,7 @@ public class AnnotationTypeFilterTests {
@Test
public
void
testInheritedAnnotationFromInterfaceDoesNotMatch
()
throws
Exception
{
MetadataReaderFactory
metadataReaderFactory
=
new
SimpleMetadataReaderFactory
();
String
classUnderTest
=
"org.springframework.core.type.AnnotationTypeFilterTests$Some
SubClassOf
SomeComponentInterface"
;
String
classUnderTest
=
"org.springframework.core.type.AnnotationTypeFilterTests$Some
ClassWith
SomeComponentInterface"
;
MetadataReader
metadataReader
=
metadataReaderFactory
.
getMetadataReader
(
classUnderTest
);
AnnotationTypeFilter
filter
=
new
AnnotationTypeFilter
(
InheritedAnnotation
.
class
);
...
...
@@ -61,7 +61,7 @@ public class AnnotationTypeFilterTests {
@Test
public
void
testInheritedAnnotationFromBaseClassDoesMatch
()
throws
Exception
{
MetadataReaderFactory
metadataReaderFactory
=
new
SimpleMetadataReaderFactory
();
String
classUnderTest
=
"org.springframework.core.type.AnnotationTypeFilterTests$SomeSub
C
lassOfSomeComponent"
;
String
classUnderTest
=
"org.springframework.core.type.AnnotationTypeFilterTests$SomeSub
c
lassOfSomeComponent"
;
MetadataReader
metadataReader
=
metadataReaderFactory
.
getMetadataReader
(
classUnderTest
);
AnnotationTypeFilter
filter
=
new
AnnotationTypeFilter
(
InheritedAnnotation
.
class
);
...
...
@@ -94,22 +94,21 @@ public class AnnotationTypeFilterTests {
@Test
public
void
testMatchesInterfacesIfConfigured
()
throws
Exception
{
MetadataReaderFactory
metadataReaderFactory
=
new
SimpleMetadataReaderFactory
();
String
classUnderTest
=
"org.springframework.core.type.AnnotationTypeFilterTests$SomeComponentInterface"
;
String
classUnderTest
=
"org.springframework.core.type.AnnotationTypeFilterTests$SomeC
lassWithSomeC
omponentInterface"
;
MetadataReader
metadataReader
=
metadataReaderFactory
.
getMetadataReader
(
classUnderTest
);
AnnotationTypeFilter
filter
=
new
AnnotationTypeFilter
(
InheritedAnnotation
.
class
,
false
,
true
);
assertTrue
(
filter
.
match
(
metadataReader
,
metadataReaderFactory
));
ClassloadingAssertions
.
assertClassNotLoaded
(
classUnderTest
);
}
// We must use a standalone set of types to ensure that no one else is loading them
// and interfering with ClassloadingAssertions.assertClassNotLoaded()
@Inherited
private
static
@interface
InheritedAnnotation
{
private
@interface
InheritedAnnotation
{
}
...
...
@@ -119,21 +118,21 @@ public class AnnotationTypeFilterTests {
@InheritedAnnotation
private
static
interface
SomeComponentInterface
{
private
interface
SomeComponentInterface
{
}
@SuppressWarnings
(
"unused"
)
private
static
class
Some
SubClassOfSomeComponentInterface
implements
SomeComponentInterface
{
private
static
class
Some
ClassWithSomeComponentInterface
implements
Cloneable
,
SomeComponentInterface
{
}
@SuppressWarnings
(
"unused"
)
private
static
class
SomeSub
C
lassOfSomeComponent
extends
SomeComponent
{
private
static
class
SomeSub
c
lassOfSomeComponent
extends
SomeComponent
{
}
private
static
@interface
NonInheritedAnnotation
{
private
@interface
NonInheritedAnnotation
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录