Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
699d75ec
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 搜索 >>
提交
699d75ec
编写于
3月 26, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
c152d246
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
29 deletion
+38
-29
spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java
...springframework/beans/annotation/AnnotationBeanUtils.java
+4
-2
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
.../org/springframework/core/annotation/AnnotationUtils.java
+34
-27
未找到文件。
spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java
浏览文件 @
699d75ec
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -19,6 +19,7 @@ package org.springframework.beans.annotation;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Method
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.Set
;
...
...
@@ -62,7 +63,8 @@ public abstract class AnnotationBeanUtils {
public
static
void
copyPropertiesToBean
(
Annotation
ann
,
Object
bean
,
@Nullable
StringValueResolver
valueResolver
,
String
...
excludedProperties
)
{
Set
<
String
>
excluded
=
new
HashSet
<>(
Arrays
.
asList
(
excludedProperties
));
Set
<
String
>
excluded
=
(
excludedProperties
.
length
==
0
?
Collections
.
emptySet
()
:
new
HashSet
<>(
Arrays
.
asList
(
excludedProperties
)));
Method
[]
annotationProperties
=
ann
.
annotationType
().
getDeclaredMethods
();
BeanWrapper
bw
=
PropertyAccessorFactory
.
forBeanPropertyAccess
(
bean
);
for
(
Method
annotationProperty
:
annotationProperties
)
{
...
...
spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java
浏览文件 @
699d75ec
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
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.
...
...
@@ -57,14 +57,14 @@ import org.springframework.util.StringUtils;
* <p>Note that most of the features of this class are not provided by the
* JDK's introspection facilities themselves.
*
* <p>As a general rule for runtime-retained a
nnotations (e.g. for transaction
*
control, authorization, or service exposure), always use the lookup methods
*
on this class (e.g., {@link #findAnnotation(Method, Class)},
* {@link #getAnnotation(Method, Class)}
, and {@link #getAnnotations(Method)})
*
instead of the plain annotation lookup methods in the JDK. You can still
*
explicitly choose between a <em>get</em> lookup on the given class level only
*
({@link #getAnnotation(Method, Class)}) and a <em>find</em> lookup in the entire
*
inheritance hierarchy of the given
method ({@link #findAnnotation(Method, Class)}).
* <p>As a general rule for runtime-retained a
pplication annotations (e.g. for
*
transaction control, authorization, or service exposure), always use the
*
lookup methods on this class (e.g. {@link #findAnnotation(Method, Class)} or
* {@link #getAnnotation(Method, Class)}
) instead of the plain annotation lookup
*
methods in the JDK. You can still explicitly choose between a <em>get</em>
*
lookup on the given class level only ({@link #getAnnotation(Method, Class)})
*
and a <em>find</em> lookup in the entire inheritance hierarchy of the given
* method ({@link #findAnnotation(Method, Class)}).
*
* <h3>Terminology</h3>
* The terms <em>directly present</em>, <em>indirectly present</em>, and
...
...
@@ -449,7 +449,13 @@ public abstract class AnnotationUtils {
* @since 4.2
*/
@Nullable
public
static
<
A
extends
Annotation
>
A
findAnnotation
(
AnnotatedElement
annotatedElement
,
Class
<
A
>
annotationType
)
{
public
static
<
A
extends
Annotation
>
A
findAnnotation
(
AnnotatedElement
annotatedElement
,
@Nullable
Class
<
A
>
annotationType
)
{
if
(
annotationType
==
null
)
{
return
null
;
}
// Do NOT store result in the findAnnotationCache since doing so could break
// findAnnotation(Class, Class) and findAnnotation(Method, Class).
A
ann
=
findAnnotation
(
annotatedElement
,
annotationType
,
new
HashSet
<>());
...
...
@@ -697,7 +703,7 @@ public abstract class AnnotationUtils {
* @return the first matching annotation, or {@code null} if not found
*/
@Nullable
public
static
<
A
extends
Annotation
>
A
findAnnotation
(
Class
<?>
clazz
,
Class
<
A
>
annotationType
)
{
public
static
<
A
extends
Annotation
>
A
findAnnotation
(
Class
<?>
clazz
,
@Nullable
Class
<
A
>
annotationType
)
{
return
findAnnotation
(
clazz
,
annotationType
,
true
);
}
...
...
@@ -793,8 +799,8 @@ public abstract class AnnotationUtils {
* @param annotationType the annotation type to look for
* @param clazz the class to check for the annotation on (may be {@code null})
* @return the first {@link Class} in the inheritance hierarchy that
* declares an annotation of the specified {@code annotationType},
or
* {@code null} if not found
* declares an annotation of the specified {@code annotationType},
*
or
{@code null} if not found
* @see Class#isAnnotationPresent(Class)
* @see Class#getDeclaredAnnotations()
* @see #findAnnotationDeclaringClassForTypes(List, Class)
...
...
@@ -825,7 +831,7 @@ public abstract class AnnotationUtils {
* one of several candidate {@linkplain Annotation annotations}, so we
* need to handle this explicitly.
* @param annotationTypes the annotation types to look for
* @param clazz the class to check for the annotation
s on, or {@code null}
* @param clazz the class to check for the annotation
on (may be {@code null})
* @return the first {@link Class} in the inheritance hierarchy that
* declares an annotation of at least one of the specified
* {@code annotationTypes}, or {@code null} if not found
...
...
@@ -1044,7 +1050,9 @@ public abstract class AnnotationUtils {
* corresponding attribute values as values (never {@code null})
* @see #getAnnotationAttributes(Annotation, boolean, boolean)
*/
public
static
Map
<
String
,
Object
>
getAnnotationAttributes
(
Annotation
annotation
,
boolean
classValuesAsString
)
{
public
static
Map
<
String
,
Object
>
getAnnotationAttributes
(
Annotation
annotation
,
boolean
classValuesAsString
)
{
return
getAnnotationAttributes
(
annotation
,
classValuesAsString
,
false
);
}
...
...
@@ -1064,8 +1072,8 @@ public abstract class AnnotationUtils {
* and corresponding attribute values as values (never {@code null})
* @since 3.1.1
*/
public
static
AnnotationAttributes
getAnnotationAttributes
(
Annotation
annotation
,
boolean
classValuesAsString
,
boolean
nestedAnnotationsAsMap
)
{
public
static
AnnotationAttributes
getAnnotationAttributes
(
Annotation
annotation
,
boolean
classValuesAsString
,
boolean
nestedAnnotationsAsMap
)
{
return
getAnnotationAttributes
(
null
,
annotation
,
classValuesAsString
,
nestedAnnotationsAsMap
);
}
...
...
@@ -1083,7 +1091,9 @@ public abstract class AnnotationUtils {
* @since 4.2
* @see #getAnnotationAttributes(AnnotatedElement, Annotation, boolean, boolean)
*/
public
static
AnnotationAttributes
getAnnotationAttributes
(
@Nullable
AnnotatedElement
annotatedElement
,
Annotation
annotation
)
{
public
static
AnnotationAttributes
getAnnotationAttributes
(
@Nullable
AnnotatedElement
annotatedElement
,
Annotation
annotation
)
{
return
getAnnotationAttributes
(
annotatedElement
,
annotation
,
false
,
false
);
}
...
...
@@ -1149,8 +1159,8 @@ public abstract class AnnotationUtils {
* @since 4.2
* @see #postProcessAnnotationAttributes
*/
static
AnnotationAttributes
retrieveAnnotationAttributes
(
@Nullable
Object
annotatedElement
,
Annotation
annotation
,
boolean
classValuesAsString
,
boolean
nestedAnnotationsAsMap
)
{
static
AnnotationAttributes
retrieveAnnotationAttributes
(
@Nullable
Object
annotatedElement
,
Annotation
annotation
,
boolean
classValuesAsString
,
boolean
nestedAnnotationsAsMap
)
{
Class
<?
extends
Annotation
>
annotationType
=
annotation
.
annotationType
();
AnnotationAttributes
attributes
=
new
AnnotationAttributes
(
annotationType
);
...
...
@@ -1432,8 +1442,8 @@ public abstract class AnnotationUtils {
}
catch
(
InvocationTargetException
ex
)
{
rethrowAnnotationConfigurationException
(
ex
.
getTargetException
());
throw
new
IllegalStateException
(
"Could not obtain value for annotation attribute '"
+
attributeName
+
"' in "
+
annotation
,
ex
);
throw
new
IllegalStateException
(
"Could not obtain value for annotation attribute '"
+
attributeName
+
"' in "
+
annotation
,
ex
);
}
catch
(
Throwable
ex
)
{
handleIntrospectionFailure
(
annotation
.
getClass
(),
ex
);
...
...
@@ -1462,10 +1472,7 @@ public abstract class AnnotationUtils {
*/
@Nullable
public
static
Object
getDefaultValue
(
@Nullable
Annotation
annotation
,
@Nullable
String
attributeName
)
{
if
(
annotation
==
null
)
{
return
null
;
}
return
getDefaultValue
(
annotation
.
annotationType
(),
attributeName
);
return
(
annotation
!=
null
?
getDefaultValue
(
annotation
.
annotationType
(),
attributeName
)
:
null
);
}
/**
...
...
@@ -2042,7 +2049,7 @@ public abstract class AnnotationUtils {
private
final
Set
<
A
>
result
=
new
LinkedHashSet
<>();
AnnotationCollector
(
Class
<
A
>
annotationType
,
@Nullable
Class
<?
extends
Annotation
>
containerAnnotationType
)
{
AnnotationCollector
(
Class
<
A
>
annotationType
,
@Nullable
Class
<?
extends
Annotation
>
containerAnnotationType
)
{
this
.
annotationType
=
annotationType
;
this
.
containerAnnotationType
=
(
containerAnnotationType
!=
null
?
containerAnnotationType
:
resolveContainerAnnotationType
(
annotationType
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录