Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
c2997f4d
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 搜索 >>
提交
c2997f4d
编写于
12月 01, 2011
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
backported Java 6 visibility bridge method pair (SPR-8660)
上级
0150000d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
15 deletion
+32
-15
org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
...tory/annotation/AutowiredAnnotationBeanPostProcessor.java
+12
-14
org.springframework.core/src/main/java/org/springframework/core/BridgeMethodResolver.java
...n/java/org/springframework/core/BridgeMethodResolver.java
+20
-1
未找到文件。
org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
浏览文件 @
c2997f4d
...
...
@@ -62,8 +62,11 @@ import org.springframework.util.ReflectionUtils;
/**
* {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation
* that autowires annotated fields, setter methods and arbitrary config methods.
* Such members to be injected are detected through a Java 5 annotation:
* by default, Spring's @{@link Autowired} and @{@link Value} annotations.
* Such members to be injected are detected through a Java 5 annotation: by default,
* Spring's {@link Autowired @Autowired} and {@link Value @Value} annotations.
*
* <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation,
* if available, as a direct alternative to Spring's own <code>@Autowired</code>.
*
* <p>Only one constructor (at max) of any given bean class may carry this
* annotation with the 'required' parameter set to <code>true</code>,
...
...
@@ -78,14 +81,10 @@ import org.springframework.util.ReflectionUtils;
* <p>Fields are injected right after construction of a bean, before any
* config methods are invoked. Such a config field does not have to be public.
*
* <p>Config methods may have an arbitrary name and any number of arguments;
* each of those arguments will be autowired with a matching bean in the
* Spring container. Bean property setter methods are effectively just
* a special case of such a general config method. Such config methods
* do not have to be public.
*
* <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation, if
* available.
* <p>Config methods may have an arbitrary name and any number of arguments; each of
* those arguments will be autowired with a matching bean in the Spring container.
* Bean property setter methods are effectively just a special case of such a
* general config method. Config methods do not have to be public.
*
* <p>Note: A default AutowiredAnnotationBeanPostProcessor will be registered
* by the "context:annotation-config" and "context:component-scan" XML tags.
...
...
@@ -343,7 +342,9 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
}
}
for
(
Method
method
:
targetClass
.
getDeclaredMethods
())
{
Annotation
annotation
=
findAutowiredAnnotation
(
method
);
Method
bridgedMethod
=
BridgeMethodResolver
.
findBridgedMethod
(
method
);
Annotation
annotation
=
BridgeMethodResolver
.
isVisibilityBridgeMethodPair
(
method
,
bridgedMethod
)
?
findAutowiredAnnotation
(
bridgedMethod
)
:
findAutowiredAnnotation
(
method
);
if
(
annotation
!=
null
&&
method
.
equals
(
ClassUtils
.
getMostSpecificMethod
(
method
,
clazz
)))
{
if
(
Modifier
.
isStatic
(
method
.
getModifiers
()))
{
if
(
logger
.
isWarnEnabled
())
{
...
...
@@ -371,9 +372,6 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
private
Annotation
findAutowiredAnnotation
(
AccessibleObject
ao
)
{
for
(
Class
<?
extends
Annotation
>
type
:
this
.
autowiredAnnotationTypes
)
{
if
(
ao
instanceof
Method
)
{
ao
=
BridgeMethodResolver
.
findBridgedMethod
((
Method
)
ao
);
}
Annotation
annotation
=
ao
.
getAnnotation
(
type
);
if
(
annotation
!=
null
)
{
return
annotation
;
...
...
org.springframework.core/src/main/java/org/springframework/core/BridgeMethodResolver.java
浏览文件 @
c2997f4d
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
11
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.
...
...
@@ -25,6 +25,7 @@ import java.util.Arrays;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ReflectionUtils
;
...
...
@@ -210,4 +211,22 @@ public abstract class BridgeMethodResolver {
return
ReflectionUtils
.
findMethod
(
type
,
bridgeMethod
.
getName
(),
bridgeMethod
.
getParameterTypes
());
}
/**
* Compare the signatures of the bridge method and the method which it bridges. If
* the parameter and return types are the same, it is a 'visibility' bridge method
* introduced in Java 6 to fix http://bugs.sun.com/view_bug.do?bug_id=6342411.
* See also http://stas-blogspot.blogspot.com/2010/03/java-bridge-methods-explained.html
* @return whether signatures match as described
*/
public
static
boolean
isVisibilityBridgeMethodPair
(
Method
bridgeMethod
,
Method
bridgedMethod
)
{
Assert
.
isTrue
(
bridgeMethod
!=
null
);
Assert
.
isTrue
(
bridgedMethod
!=
null
);
if
(
bridgeMethod
==
bridgedMethod
)
{
return
true
;
}
return
Arrays
.
equals
(
bridgeMethod
.
getParameterTypes
(),
bridgedMethod
.
getParameterTypes
())
&&
bridgeMethod
.
getReturnType
().
equals
(
bridgedMethod
.
getReturnType
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录