Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Meiracle
spring-framework
提交
ec781650
S
spring-framework
项目概览
Meiracle
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
ec781650
编写于
12月 11, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Component scanning ignores attributes and meta-annotations on non-public annotations
Issue: SPR-11091 (cherry picked from commit
161819f1
)
上级
e4fb72f6
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
76 addition
and
31 deletion
+76
-31
spring-context/src/test/java/example/scannable/CustomAnnotations.java
...xt/src/test/java/example/scannable/CustomAnnotations.java
+34
-0
spring-context/src/test/java/example/scannable/CustomComponent.java
...text/src/test/java/example/scannable/CustomComponent.java
+2
-1
spring-context/src/test/java/example/scannable/MessageBean.java
...-context/src/test/java/example/scannable/MessageBean.java
+3
-1
spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java
...type/classreading/AnnotationAttributesReadingVisitor.java
+37
-29
未找到文件。
spring-context/src/test/java/example/scannable/CustomAnnotations.java
0 → 100644
浏览文件 @
ec781650
/*
* Copyright 2002-2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
example.scannable
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
public
class
CustomAnnotations
{
@Retention
(
RetentionPolicy
.
RUNTIME
)
private
@interface
PrivateAnnotation
{
String
value
();
}
@Retention
(
RetentionPolicy
.
RUNTIME
)
@PrivateAnnotation
(
"special"
)
public
@interface
SpecialAnnotation
{
}
}
spring-context/src/test/java/example/scannable/CustomComponent.java
浏览文件 @
ec781650
/*
* Copyright 2002-20
07
the original author or authors.
* Copyright 2002-20
13
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.
...
...
@@ -28,6 +28,7 @@ import java.lang.annotation.Target;
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
@CustomAnnotations
.
SpecialAnnotation
public
@interface
CustomComponent
{
}
spring-context/src/test/java/example/scannable/MessageBean.java
浏览文件 @
ec781650
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
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.
...
...
@@ -20,6 +20,7 @@ package example.scannable;
* @author Mark Fisher
*/
@CustomComponent
@CustomAnnotations
.
SpecialAnnotation
public
class
MessageBean
{
private
String
message
;
...
...
@@ -32,6 +33,7 @@ public class MessageBean {
this
.
message
=
message
;
}
@CustomAnnotations
.
SpecialAnnotation
public
String
getMessage
()
{
return
this
.
message
;
}
...
...
spring-core/src/main/java/org/springframework/core/type/classreading/AnnotationAttributesReadingVisitor.java
浏览文件 @
ec781650
...
...
@@ -20,6 +20,7 @@ import java.lang.annotation.Annotation;
import
java.lang.reflect.Array
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.util.ArrayList
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
...
...
@@ -28,6 +29,7 @@ import java.util.Set;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.asm.AnnotationVisitor
;
import
org.springframework.asm.SpringAsmInfo
;
import
org.springframework.asm.Type
;
...
...
@@ -36,7 +38,6 @@ import org.springframework.core.annotation.AnnotationUtils;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ReflectionUtils
;
/**
* @author Chris Beams
* @author Juergen Hoeller
...
...
@@ -169,12 +170,11 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
public
final
void
visitEnd
()
{
try
{
Class
<?>
annotationClass
=
this
.
classLoader
.
loadClass
(
this
.
annotationType
);
this
.
doVisitEnd
(
annotationClass
);
doVisitEnd
(
annotationClass
);
}
catch
(
ClassNotFoundException
ex
)
{
this
.
logger
.
debug
(
"Failed to classload type while reading annotation "
+
"metadata. This is a non-fatal error, but certain annotation "
+
"metadata may be unavailable."
,
ex
);
this
.
logger
.
debug
(
"Failed to class-load type while reading annotation metadata. "
+
"This is a non-fatal error, but certain annotation metadata may be unavailable."
,
ex
);
}
}
...
...
@@ -183,6 +183,9 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
}
private
void
registerDefaultValues
(
Class
<?>
annotationClass
)
{
// Only do further scanning for public annotations; we'd run into IllegalAccessExceptions
// otherwise, and don't want to mess with accessibility in a SecurityManager environment.
if
(
Modifier
.
isPublic
(
annotationClass
.
getModifiers
()))
{
// Check declared default values of attributes in the annotation type.
Method
[]
annotationAttributes
=
annotationClass
.
getMethods
();
for
(
Method
annotationAttribute
:
annotationAttributes
)
{
...
...
@@ -191,7 +194,7 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
if
(
defaultValue
!=
null
&&
!
this
.
attributes
.
containsKey
(
attributeName
))
{
if
(
defaultValue
instanceof
Annotation
)
{
defaultValue
=
AnnotationAttributes
.
fromMap
(
AnnotationUtils
.
getAnnotationAttributes
((
Annotation
)
defaultValue
,
false
,
true
));
AnnotationUtils
.
getAnnotationAttributes
((
Annotation
)
defaultValue
,
false
,
true
));
}
else
if
(
defaultValue
instanceof
Annotation
[])
{
Annotation
[]
realAnnotations
=
(
Annotation
[])
defaultValue
;
...
...
@@ -206,6 +209,7 @@ class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVi
}
}
}
}
}
...
...
@@ -251,6 +255,9 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
Set
<
String
>
metaAnnotationTypeNames
=
new
LinkedHashSet
<
String
>();
for
(
Annotation
metaAnnotation
:
annotationClass
.
getAnnotations
())
{
metaAnnotationTypeNames
.
add
(
metaAnnotation
.
annotationType
().
getName
());
// Only do further scanning for public annotations; we'd run into IllegalAccessExceptions
// otherwise, and don't want to mess with accessibility in a SecurityManager environment.
if
(
Modifier
.
isPublic
(
metaAnnotation
.
annotationType
().
getModifiers
()))
{
if
(!
this
.
attributesMap
.
containsKey
(
metaAnnotation
.
annotationType
().
getName
()))
{
this
.
attributesMap
.
put
(
metaAnnotation
.
annotationType
().
getName
(),
AnnotationUtils
.
getAnnotationAttributes
(
metaAnnotation
,
true
,
true
));
...
...
@@ -259,6 +266,7 @@ final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttrib
metaAnnotationTypeNames
.
add
(
metaMetaAnnotation
.
annotationType
().
getName
());
}
}
}
if
(
this
.
metaAnnotationMap
!=
null
)
{
this
.
metaAnnotationMap
.
put
(
annotationClass
.
getName
(),
metaAnnotationTypeNames
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录