Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
0c2e8a62
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,发现更多精彩内容 >>
提交
0c2e8a62
编写于
9月 13, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent callbacks for TypeFilters, ImportSelectors and ImportBeanDefinitionRegistrars
Issue: SPR-14686
上级
5405c07d
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
91 addition
and
74 deletion
+91
-74
spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
...n/java/org/springframework/beans/factory/BeanFactory.java
+14
-11
spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
...ork/context/annotation/ComponentScanAnnotationParser.java
+7
-36
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
...ramework/context/annotation/ConfigurationClassParser.java
+5
-27
spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java
...ringframework/context/annotation/ParserStrategyUtils.java
+65
-0
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java
浏览文件 @
0c2e8a62
...
...
@@ -67,24 +67,27 @@ import org.springframework.core.ResolvableType;
* 1. BeanNameAware's {@code setBeanName}<br>
* 2. BeanClassLoaderAware's {@code setBeanClassLoader}<br>
* 3. BeanFactoryAware's {@code setBeanFactory}<br>
* 4. ResourceLoaderAware's {@code setResourceLoader}
* 4. EnvironmentAware's {@code setEnvironment}
* 5. EmbeddedValueResolverAware's {@code setEmbeddedValueResolver}
* 6. ResourceLoaderAware's {@code setResourceLoader}
* (only applicable when running in an application context)<br>
*
5
. ApplicationEventPublisherAware's {@code setApplicationEventPublisher}
*
7
. ApplicationEventPublisherAware's {@code setApplicationEventPublisher}
* (only applicable when running in an application context)<br>
*
6
. MessageSourceAware's {@code setMessageSource}
*
8
. MessageSourceAware's {@code setMessageSource}
* (only applicable when running in an application context)<br>
*
7
. ApplicationContextAware's {@code setApplicationContext}
*
9
. ApplicationContextAware's {@code setApplicationContext}
* (only applicable when running in an application context)<br>
*
8
. ServletContextAware's {@code setServletContext}
*
10
. ServletContextAware's {@code setServletContext}
* (only applicable when running in a web application context)<br>
*
9
. {@code postProcessBeforeInitialization} methods of BeanPostProcessors<br>
* 1
0
. InitializingBean's {@code afterPropertiesSet}<br>
* 1
1
. a custom init-method definition<br>
* 1
2
. {@code postProcessAfterInitialization} methods of BeanPostProcessors
*
11
. {@code postProcessBeforeInitialization} methods of BeanPostProcessors<br>
* 1
2
. InitializingBean's {@code afterPropertiesSet}<br>
* 1
3
. a custom init-method definition<br>
* 1
4
. {@code postProcessAfterInitialization} methods of BeanPostProcessors
*
* <p>On shutdown of a bean factory, the following lifecycle methods apply:<br>
* 1. DisposableBean's {@code destroy}<br>
* 2. a custom destroy-method definition
* 1. {@code postProcessBeforeDestruction} methods of DestructionAwareBeanPostProcessors
* 2. DisposableBean's {@code destroy}<br>
* 3. a custom destroy-method definition
*
* @author Rod Johnson
* @author Juergen Hoeller
...
...
spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
浏览文件 @
0c2e8a62
...
...
@@ -25,17 +25,10 @@ import java.util.Set;
import
java.util.regex.Pattern
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.Aware
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.config.BeanDefinitionHolder
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.beans.factory.support.BeanNameGenerator
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.ResourceLoaderAware
;
import
org.springframework.core.annotation.AnnotationAttributes
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.ResourceLoader
;
...
...
@@ -61,16 +54,16 @@ import org.springframework.util.StringUtils;
*/
class
ComponentScanAnnotationParser
{
private
final
ResourceLoader
resourceLoader
;
private
final
Environment
environment
;
private
final
BeanDefinitionRegistry
registry
;
private
final
ResourceLoader
resourceLoader
;
private
final
BeanNameGenerator
beanNameGenerator
;
private
final
BeanDefinitionRegistry
registry
;
public
ComponentScanAnnotationParser
(
ResourceLoader
resourceLoader
,
Environment
environment
,
public
ComponentScanAnnotationParser
(
Environment
environment
,
ResourceLoader
resourceLoader
,
BeanNameGenerator
beanNameGenerator
,
BeanDefinitionRegistry
registry
)
{
this
.
resourceLoader
=
resourceLoader
;
...
...
@@ -90,7 +83,7 @@ class ComponentScanAnnotationParser {
scanner
.
setResourceLoader
(
this
.
resourceLoader
);
Class
<?
extends
BeanNameGenerator
>
generatorClass
=
componentScan
.
getClass
(
"nameGenerator"
);
boolean
useInheritedGenerator
=
BeanNameGenerator
.
class
==
generatorClass
;
boolean
useInheritedGenerator
=
(
BeanNameGenerator
.
class
==
generatorClass
)
;
scanner
.
setBeanNameGenerator
(
useInheritedGenerator
?
this
.
beanNameGenerator
:
BeanUtils
.
instantiateClass
(
generatorClass
));
...
...
@@ -164,7 +157,8 @@ class ComponentScanAnnotationParser {
Assert
.
isAssignable
(
TypeFilter
.
class
,
filterClass
,
"An error occurred while processing a @ComponentScan CUSTOM type filter: "
);
TypeFilter
filter
=
BeanUtils
.
instantiateClass
(
filterClass
,
TypeFilter
.
class
);
invokeAwareMethods
(
filter
);
ParserStrategyUtils
.
invokeAwareMethods
(
filter
,
this
.
environment
,
this
.
resourceLoader
,
this
.
registry
);
typeFilters
.
add
(
filter
);
break
;
default
:
...
...
@@ -188,27 +182,4 @@ class ComponentScanAnnotationParser {
return
typeFilters
;
}
/**
* Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
* {@link BeanFactoryAware} contracts if implemented by the given {@code filter}.
*/
private
void
invokeAwareMethods
(
TypeFilter
filter
)
{
if
(
filter
instanceof
Aware
)
{
if
(
filter
instanceof
EnvironmentAware
)
{
((
EnvironmentAware
)
filter
).
setEnvironment
(
this
.
environment
);
}
if
(
filter
instanceof
ResourceLoaderAware
)
{
((
ResourceLoaderAware
)
filter
).
setResourceLoader
(
this
.
resourceLoader
);
}
if
(
filter
instanceof
BeanClassLoaderAware
)
{
ClassLoader
classLoader
=
(
this
.
registry
instanceof
ConfigurableBeanFactory
?
((
ConfigurableBeanFactory
)
this
.
registry
).
getBeanClassLoader
()
:
this
.
resourceLoader
.
getClassLoader
());
((
BeanClassLoaderAware
)
filter
).
setBeanClassLoader
(
classLoader
);
}
if
(
filter
instanceof
BeanFactoryAware
&&
this
.
registry
instanceof
BeanFactory
)
{
((
BeanFactoryAware
)
filter
).
setBeanFactory
((
BeanFactory
)
this
.
registry
);
}
}
}
}
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
浏览文件 @
0c2e8a62
...
...
@@ -158,7 +158,7 @@ class ConfigurationClassParser {
this
.
resourceLoader
=
resourceLoader
;
this
.
registry
=
registry
;
this
.
componentScanParser
=
new
ComponentScanAnnotationParser
(
resourceLoader
,
environment
,
componentScanBeanNameGenerator
,
registry
);
environment
,
resourceLoader
,
componentScanBeanNameGenerator
,
registry
);
this
.
conditionEvaluator
=
new
ConditionEvaluator
(
registry
,
environment
,
resourceLoader
);
}
...
...
@@ -509,7 +509,8 @@ class ConfigurationClassParser {
// Candidate class is an ImportSelector -> delegate to it to determine imports
Class
<?>
candidateClass
=
candidate
.
loadClass
();
ImportSelector
selector
=
BeanUtils
.
instantiateClass
(
candidateClass
,
ImportSelector
.
class
);
invokeAwareMethods
(
selector
);
ParserStrategyUtils
.
invokeAwareMethods
(
selector
,
this
.
environment
,
this
.
resourceLoader
,
this
.
registry
);
if
(
this
.
deferredImportSelectors
!=
null
&&
selector
instanceof
DeferredImportSelector
)
{
this
.
deferredImportSelectors
.
add
(
new
DeferredImportSelectorHolder
(
configClass
,
(
DeferredImportSelector
)
selector
));
...
...
@@ -526,7 +527,8 @@ class ConfigurationClassParser {
Class
<?>
candidateClass
=
candidate
.
loadClass
();
ImportBeanDefinitionRegistrar
registrar
=
BeanUtils
.
instantiateClass
(
candidateClass
,
ImportBeanDefinitionRegistrar
.
class
);
invokeAwareMethods
(
registrar
);
ParserStrategyUtils
.
invokeAwareMethods
(
registrar
,
this
.
environment
,
this
.
resourceLoader
,
this
.
registry
);
configClass
.
addImportBeanDefinitionRegistrar
(
registrar
,
currentSourceClass
.
getMetadata
());
}
else
{
...
...
@@ -565,30 +567,6 @@ class ConfigurationClassParser {
return
false
;
}
/**
* Invoke {@link ResourceLoaderAware}, {@link BeanClassLoaderAware} and
* {@link BeanFactoryAware} contracts if implemented by the given {@code bean}.
*/
private
void
invokeAwareMethods
(
Object
importStrategyBean
)
{
if
(
importStrategyBean
instanceof
Aware
)
{
if
(
importStrategyBean
instanceof
EnvironmentAware
)
{
((
EnvironmentAware
)
importStrategyBean
).
setEnvironment
(
this
.
environment
);
}
if
(
importStrategyBean
instanceof
ResourceLoaderAware
)
{
((
ResourceLoaderAware
)
importStrategyBean
).
setResourceLoader
(
this
.
resourceLoader
);
}
if
(
importStrategyBean
instanceof
BeanClassLoaderAware
)
{
ClassLoader
classLoader
=
(
this
.
registry
instanceof
ConfigurableBeanFactory
?
((
ConfigurableBeanFactory
)
this
.
registry
).
getBeanClassLoader
()
:
this
.
resourceLoader
.
getClassLoader
());
((
BeanClassLoaderAware
)
importStrategyBean
).
setBeanClassLoader
(
classLoader
);
}
if
(
importStrategyBean
instanceof
BeanFactoryAware
&&
this
.
registry
instanceof
BeanFactory
)
{
((
BeanFactoryAware
)
importStrategyBean
).
setBeanFactory
((
BeanFactory
)
this
.
registry
);
}
}
}
/**
* Validate each {@link ConfigurationClass} object.
...
...
spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java
0 → 100644
浏览文件 @
0c2e8a62
/*
* Copyright 2002-2016 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
org.springframework.context.annotation
;
import
org.springframework.beans.factory.Aware
;
import
org.springframework.beans.factory.BeanClassLoaderAware
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.BeanFactoryAware
;
import
org.springframework.beans.factory.config.ConfigurableBeanFactory
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.ResourceLoaderAware
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.ResourceLoader
;
/**
* Common delegate code for the handling of parser strategies, e.g.
* {@code TypeFilter}, {@code ImportSelector}, {@code ImportBeanDefinitionRegistrar}
*
* @author Juergen Hoeller
* @since 4.3.3
*/
abstract
class
ParserStrategyUtils
{
/**
* Invoke {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
* {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
* if implemented by the given object.
*/
public
static
void
invokeAwareMethods
(
Object
parserStrategyBean
,
Environment
environment
,
ResourceLoader
resourceLoader
,
BeanDefinitionRegistry
registry
)
{
if
(
parserStrategyBean
instanceof
Aware
)
{
if
(
parserStrategyBean
instanceof
BeanClassLoaderAware
)
{
ClassLoader
classLoader
=
(
registry
instanceof
ConfigurableBeanFactory
?
((
ConfigurableBeanFactory
)
registry
).
getBeanClassLoader
()
:
resourceLoader
.
getClassLoader
());
((
BeanClassLoaderAware
)
parserStrategyBean
).
setBeanClassLoader
(
classLoader
);
}
if
(
parserStrategyBean
instanceof
BeanFactoryAware
&&
registry
instanceof
BeanFactory
)
{
((
BeanFactoryAware
)
parserStrategyBean
).
setBeanFactory
((
BeanFactory
)
registry
);
}
if
(
parserStrategyBean
instanceof
EnvironmentAware
)
{
((
EnvironmentAware
)
parserStrategyBean
).
setEnvironment
(
environment
);
}
if
(
parserStrategyBean
instanceof
ResourceLoaderAware
)
{
((
ResourceLoaderAware
)
parserStrategyBean
).
setResourceLoader
(
resourceLoader
);
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录