Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9d969587
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 搜索 >>
提交
9d969587
编写于
10月 02, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CompositePropertySource extends EnumerablePropertySource now
Issue: SPR-12292
上级
fd69ee54
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
5 deletion
+41
-5
spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java
...org/springframework/core/env/CompositePropertySource.java
+32
-1
spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java
...rg/springframework/core/env/EnumerablePropertySource.java
+5
-0
spring-core/src/main/java/org/springframework/core/env/PropertySource.java
...ain/java/org/springframework/core/env/PropertySource.java
+4
-4
未找到文件。
spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java
浏览文件 @
9d969587
...
...
@@ -17,21 +17,29 @@
package
org.springframework.core.env
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.springframework.util.StringUtils
;
/**
* Composite {@link PropertySource} implementation that iterates over a set of
* {@link PropertySource} instances. Necessary in cases where multiple property sources
* share the same name, e.g. when multiple values are supplied to {@code @PropertySource}.
*
* <p>As of Spring 4.1.2, this class extends {@link EnumerablePropertySource} instead
* of plain {@link PropertySource}, exposing {@link #getPropertyNames()} based on the
* accumulated property names from all contained sources (as far as possible).
*
* @author Chris Beams
* @author Juergen Hoeller
* @author Phillip Webb
* @since 3.1.1
*/
public
class
CompositePropertySource
extends
PropertySource
<
Object
>
{
public
class
CompositePropertySource
extends
Enumerable
PropertySource
<
Object
>
{
private
final
Set
<
PropertySource
<?>>
propertySources
=
new
LinkedHashSet
<
PropertySource
<?>>();
...
...
@@ -56,6 +64,28 @@ public class CompositePropertySource extends PropertySource<Object> {
return
null
;
}
@Override
public
boolean
containsProperty
(
String
name
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
if
(
propertySource
.
containsProperty
(
name
))
{
return
true
;
}
}
return
false
;
}
@Override
public
String
[]
getPropertyNames
()
{
Set
<
String
>
names
=
new
LinkedHashSet
<
String
>();
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
if
(
propertySource
instanceof
EnumerablePropertySource
)
{
names
.
addAll
(
Arrays
.
asList
(((
EnumerablePropertySource
<?>)
propertySource
).
getPropertyNames
()));
}
}
return
StringUtils
.
toStringArray
(
names
);
}
/**
* Add the given {@link PropertySource} to the end of the chain.
* @param propertySource the PropertySource to add
...
...
@@ -84,6 +114,7 @@ public class CompositePropertySource extends PropertySource<Object> {
return
this
.
propertySources
;
}
@Override
public
String
toString
()
{
return
String
.
format
(
"%s [name='%s', propertySources=%s]"
,
...
...
spring-core/src/main/java/org/springframework/core/env/EnumerablePropertySource.java
浏览文件 @
9d969587
...
...
@@ -47,6 +47,11 @@ public abstract class EnumerablePropertySource<T> extends PropertySource<T> {
super
(
name
,
source
);
}
@SuppressWarnings
(
"unchecked"
)
protected
EnumerablePropertySource
(
String
name
)
{
super
(
name
);
}
/**
* Return whether this {@code PropertySource} contains a property with the given name.
...
...
spring-core/src/main/java/org/springframework/core/env/PropertySource.java
浏览文件 @
9d969587
...
...
@@ -75,10 +75,10 @@ public abstract class PropertySource<T> {
}
/**
* Create a new {@code PropertySource} with the given name and with a new
{@code Object}
* instance as the underlying source.
* <p>Often useful in testing scenarios when creating anonymous implementations
that
* never query an actual source but rather return hard-coded values.
* Create a new {@code PropertySource} with the given name and with a new
*
{@code Object}
instance as the underlying source.
* <p>Often useful in testing scenarios when creating anonymous implementations
*
that
never query an actual source but rather return hard-coded values.
*/
@SuppressWarnings
(
"unchecked"
)
public
PropertySource
(
String
name
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录