Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dk131072
spring-framework
提交
859497b1
S
spring-framework
项目概览
dk131072
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
859497b1
编写于
4月 09, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
@resource
names may use ${...} placeholders (SPR-5656)
上级
3cac9267
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
33 addition
and
14 deletion
+33
-14
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
...amework/beans/factory/config/ConfigurableBeanFactory.java
+7
-0
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
...gframework/beans/factory/support/AbstractBeanFactory.java
+1
-6
org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
...context/annotation/CommonAnnotationBeanPostProcessor.java
+7
-5
org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java
...xt/annotation/CommonAnnotationBeanPostProcessorTests.java
+18
-3
未找到文件。
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/ConfigurableBeanFactory.java
浏览文件 @
859497b1
...
...
@@ -187,6 +187,13 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
*/
void
addEmbeddedValueResolver
(
StringValueResolver
valueResolver
);
/**
* Resolve the given embedded value, e.g. an annotation attribute.
* @param value the value to resolve
* @return the resolved value (may be the original value as-is)
*/
String
resolveEmbeddedValue
(
String
value
);
/**
* Add a new BeanPostProcessor that will get applied to beans created
* by this factory. To be invoked during factory configuration.
...
...
org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java
浏览文件 @
859497b1
...
...
@@ -660,12 +660,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
this
.
embeddedValueResolvers
.
add
(
valueResolver
);
}
/**
* Resolve the given embedded value, e.g. an annotation attribute.
* @param value the value to resolve
* @return the resolved value (may be the original value as-is)
*/
protected
String
resolveEmbeddedValue
(
String
value
)
{
public
String
resolveEmbeddedValue
(
String
value
)
{
String
result
=
value
;
for
(
StringValueResolver
resolver
:
this
.
embeddedValueResolvers
)
{
result
=
resolver
.
resolveStringValue
(
result
);
...
...
org.springframework.context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
浏览文件 @
859497b1
/*
* Copyright 2002-200
8
the original author or authors.
* Copyright 2002-200
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.
...
...
@@ -34,7 +34,6 @@ import java.util.LinkedHashSet;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.ConcurrentHashMap
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
javax.annotation.Resource
;
...
...
@@ -422,8 +421,8 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
protected
Object
autowireResource
(
BeanFactory
factory
,
LookupElement
element
,
String
requestingBeanName
)
throws
BeansException
{
Object
resource
=
null
;
Set
<
String
>
autowiredBeanNames
=
null
;
Object
resource
;
Set
<
String
>
autowiredBeanNames
;
String
name
=
element
.
name
;
if
(
this
.
fallbackToDefaultTypeMatch
&&
element
.
isDefaultName
&&
...
...
@@ -521,6 +520,9 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
resourceName
=
Introspector
.
decapitalize
(
resourceName
.
substring
(
3
));
}
}
else
if
(
beanFactory
instanceof
ConfigurableBeanFactory
){
resourceName
=
((
ConfigurableBeanFactory
)
beanFactory
).
resolveEmbeddedValue
(
resourceName
);
}
if
(
resourceType
!=
null
&&
!
Object
.
class
.
equals
(
resourceType
))
{
checkResourceType
(
resourceType
);
}
...
...
@@ -588,7 +590,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
@Override
protected
Object
getResourceToInject
(
Object
target
,
String
requestingBeanName
)
{
Service
service
=
null
;
Service
service
;
try
{
service
=
(
Service
)
getResource
(
this
,
requestingBeanName
);
}
...
...
org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java
浏览文件 @
859497b1
...
...
@@ -16,6 +16,8 @@
package
org.springframework.context.annotation
;
import
java.util.Properties
;
import
static
org
.
junit
.
Assert
.*;
import
javax.annotation.PostConstruct
;
...
...
@@ -31,6 +33,7 @@ import org.springframework.beans.TestBean;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
;
import
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor
;
import
org.springframework.beans.factory.support.DefaultListableBeanFactory
;
import
org.springframework.beans.factory.support.RootBeanDefinition
;
...
...
@@ -171,10 +174,16 @@ public class CommonAnnotationBeanPostProcessorTests {
public
void
testExtendedResourceInjection
()
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
CommonAnnotationBeanPostProcessor
bpp
=
new
CommonAnnotationBeanPostProcessor
();
bpp
.
set
Resource
Factory
(
bf
);
bpp
.
set
Bean
Factory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerResolvableDependency
(
BeanFactory
.
class
,
bf
);
PropertyPlaceholderConfigurer
ppc
=
new
PropertyPlaceholderConfigurer
();
Properties
props
=
new
Properties
();
props
.
setProperty
(
"tb"
,
"testBean3"
);
ppc
.
setProperties
(
props
);
ppc
.
postProcessBeanFactory
(
bf
);
bf
.
registerBeanDefinition
(
"annotatedBean"
,
new
RootBeanDefinition
(
ExtendedResourceInjectionBean
.
class
));
bf
.
registerBeanDefinition
(
"annotatedBean2"
,
new
RootBeanDefinition
(
NamedResourceInjectionBean
.
class
));
TestBean
tb
=
new
TestBean
();
...
...
@@ -212,10 +221,16 @@ public class CommonAnnotationBeanPostProcessorTests {
public
void
testExtendedResourceInjectionWithOverriding
()
{
DefaultListableBeanFactory
bf
=
new
DefaultListableBeanFactory
();
CommonAnnotationBeanPostProcessor
bpp
=
new
CommonAnnotationBeanPostProcessor
();
bpp
.
set
Resource
Factory
(
bf
);
bpp
.
set
Bean
Factory
(
bf
);
bf
.
addBeanPostProcessor
(
bpp
);
bf
.
registerResolvableDependency
(
BeanFactory
.
class
,
bf
);
PropertyPlaceholderConfigurer
ppc
=
new
PropertyPlaceholderConfigurer
();
Properties
props
=
new
Properties
();
props
.
setProperty
(
"tb"
,
"testBean3"
);
ppc
.
setProperties
(
props
);
ppc
.
postProcessBeanFactory
(
bf
);
RootBeanDefinition
annotatedBd
=
new
RootBeanDefinition
(
ExtendedResourceInjectionBean
.
class
);
TestBean
tb5
=
new
TestBean
();
annotatedBd
.
getPropertyValues
().
addPropertyValue
(
"testBean2"
,
tb5
);
...
...
@@ -387,7 +402,7 @@ public class CommonAnnotationBeanPostProcessorTests {
super
.
setTestBean2
(
testBean2
);
}
@Resource
(
name
=
"
testBean3
"
,
type
=
ITestBean
.
class
)
@Resource
(
name
=
"
${tb}
"
,
type
=
ITestBean
.
class
)
private
void
setTestBean4
(
ITestBean
testBean4
)
{
this
.
testBean4
=
testBean4
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录