Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sesemomo
spring-framework
提交
8053fefe
S
spring-framework
项目概览
sesemomo
/
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,发现更多精彩内容 >>
提交
8053fefe
编写于
11月 03, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent support for early placeholder resolution in properties locations
Issue: SPR-10502
上级
03468fd9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
85 addition
and
8 deletion
+85
-8
spring-beans/src/main/java/org/springframework/beans/factory/xml/UtilNamespaceHandler.java
...ringframework/beans/factory/xml/UtilNamespaceHandler.java
+2
-1
spring-context/src/main/java/org/springframework/context/config/AbstractPropertyLoadingBeanDefinitionParser.java
...t/config/AbstractPropertyLoadingBeanDefinitionParser.java
+4
-2
spring-context/src/main/java/org/springframework/context/config/PropertyOverrideBeanDefinitionParser.java
.../context/config/PropertyOverrideBeanDefinitionParser.java
+4
-3
spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java
...ntext/config/PropertyPlaceholderBeanDefinitionParser.java
+3
-2
spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java
...ramework/context/config/ContextNamespaceHandlerTests.java
+50
-0
spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-location-placeholder.xml
...fig/contextNamespaceHandlerTests-location-placeholder.xml
+22
-0
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/xml/UtilNamespaceHandler.java
浏览文件 @
8053fefe
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -200,6 +200,7 @@ public class UtilNamespaceHandler extends NamespaceHandlerSupport {
String
location
=
element
.
getAttribute
(
"location"
);
if
(
StringUtils
.
hasLength
(
location
))
{
location
=
parserContext
.
getReaderContext
().
getEnvironment
().
resolvePlaceholders
(
location
);
String
[]
locations
=
StringUtils
.
commaDelimitedListToStringArray
(
location
);
builder
.
addPropertyValue
(
"locations"
,
locations
);
}
...
...
spring-context/src/main/java/org/springframework/context/config/AbstractPropertyLoadingBeanDefinitionParser.java
浏览文件 @
8053fefe
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -21,6 +21,7 @@ import org.w3c.dom.Element;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser
;
import
org.springframework.beans.factory.xml.ParserContext
;
import
org.springframework.util.StringUtils
;
/**
...
...
@@ -39,9 +40,10 @@ abstract class AbstractPropertyLoadingBeanDefinitionParser extends AbstractSingl
}
@Override
protected
void
doParse
(
Element
element
,
BeanDefinitionBuilder
builder
)
{
protected
void
doParse
(
Element
element
,
ParserContext
parserContext
,
BeanDefinitionBuilder
builder
)
{
String
location
=
element
.
getAttribute
(
"location"
);
if
(
StringUtils
.
hasLength
(
location
))
{
location
=
parserContext
.
getReaderContext
().
getEnvironment
().
resolvePlaceholders
(
location
);
String
[]
locations
=
StringUtils
.
commaDelimitedListToStringArray
(
location
);
builder
.
addPropertyValue
(
"locations"
,
locations
);
}
...
...
spring-context/src/main/java/org/springframework/context/config/PropertyOverrideBeanDefinitionParser.java
浏览文件 @
8053fefe
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -20,6 +20,7 @@ import org.w3c.dom.Element;
import
org.springframework.beans.factory.config.PropertyOverrideConfigurer
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.xml.ParserContext
;
/**
* Parser for the <context:property-override/> element.
...
...
@@ -36,8 +37,8 @@ class PropertyOverrideBeanDefinitionParser extends AbstractPropertyLoadingBeanDe
}
@Override
protected
void
doParse
(
Element
element
,
BeanDefinitionBuilder
builder
)
{
super
.
doParse
(
element
,
builder
);
protected
void
doParse
(
Element
element
,
ParserContext
parserContext
,
BeanDefinitionBuilder
builder
)
{
super
.
doParse
(
element
,
parserContext
,
builder
);
builder
.
addPropertyValue
(
"ignoreInvalidKeys"
,
Boolean
.
valueOf
(
element
.
getAttribute
(
"ignore-unresolvable"
)));
...
...
spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java
浏览文件 @
8053fefe
...
...
@@ -20,6 +20,7 @@ import org.w3c.dom.Element;
import
org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.xml.ParserContext
;
import
org.springframework.context.support.PropertySourcesPlaceholderConfigurer
;
import
org.springframework.util.StringUtils
;
...
...
@@ -54,8 +55,8 @@ class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBea
}
@Override
protected
void
doParse
(
Element
element
,
BeanDefinitionBuilder
builder
)
{
super
.
doParse
(
element
,
builder
);
protected
void
doParse
(
Element
element
,
ParserContext
parserContext
,
BeanDefinitionBuilder
builder
)
{
super
.
doParse
(
element
,
parserContext
,
builder
);
builder
.
addPropertyValue
(
"ignoreUnresolvablePlaceholders"
,
Boolean
.
valueOf
(
element
.
getAttribute
(
"ignore-unresolvable"
)));
...
...
spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java
浏览文件 @
8053fefe
...
...
@@ -16,12 +16,14 @@
package
org.springframework.context.config
;
import
java.io.FileNotFoundException
;
import
java.util.Calendar
;
import
java.util.Date
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.beans.FatalBeanException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.context.support.GenericXmlApplicationContext
;
...
...
@@ -89,6 +91,54 @@ public class ContextNamespaceHandlerTests {
assertEquals
(
"maps"
,
applicationContext
.
getBean
(
"spam"
));
}
@Test
public
void
propertyPlaceholderLocationWithSystemPropertyForOneLocation
()
throws
Exception
{
System
.
setProperty
(
"properties"
,
"classpath*:/org/springframework/context/config/test-*.properties"
);
try
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"contextNamespaceHandlerTests-location-placeholder.xml"
,
getClass
());
assertEquals
(
"bar"
,
applicationContext
.
getBean
(
"foo"
));
assertEquals
(
"foo"
,
applicationContext
.
getBean
(
"bar"
));
assertEquals
(
"maps"
,
applicationContext
.
getBean
(
"spam"
));
}
finally
{
System
.
clearProperty
(
"properties"
);
}
}
@Test
public
void
propertyPlaceholderLocationWithSystemPropertyForMultipleLocations
()
throws
Exception
{
System
.
setProperty
(
"properties"
,
"classpath*:/org/springframework/context/config/test-*.properties,"
+
"classpath*:/org/springframework/context/config/empty-*.properties,"
+
"classpath*:/org/springframework/context/config/missing-*.properties"
);
try
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"contextNamespaceHandlerTests-location-placeholder.xml"
,
getClass
());
assertEquals
(
"bar"
,
applicationContext
.
getBean
(
"foo"
));
assertEquals
(
"foo"
,
applicationContext
.
getBean
(
"bar"
));
assertEquals
(
"maps"
,
applicationContext
.
getBean
(
"spam"
));
}
finally
{
System
.
clearProperty
(
"properties"
);
}
}
@Test
public
void
propertyPlaceholderLocationWithSystemPropertyMissing
()
throws
Exception
{
try
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
"contextNamespaceHandlerTests-location-placeholder.xml"
,
getClass
());
assertEquals
(
"bar"
,
applicationContext
.
getBean
(
"foo"
));
assertEquals
(
"foo"
,
applicationContext
.
getBean
(
"bar"
));
assertEquals
(
"maps"
,
applicationContext
.
getBean
(
"spam"
));
}
catch
(
FatalBeanException
ex
)
{
assertTrue
(
ex
.
getRootCause
()
instanceof
FileNotFoundException
);
}
}
@Test
public
void
propertyPlaceholderIgnored
()
throws
Exception
{
ApplicationContext
applicationContext
=
new
ClassPathXmlApplicationContext
(
...
...
spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-location-placeholder.xml
0 → 100644
浏览文件 @
8053fefe
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"
>
<context:property-placeholder
location=
"${properties}"
file-encoding=
"ISO-8859-1"
trim-values=
"true"
/>
<bean
id=
"foo"
class=
"java.lang.String"
>
<constructor-arg
value=
"${foo}"
/>
</bean>
<bean
id=
"bar"
class=
"java.lang.String"
>
<constructor-arg
value=
"${bar}"
/>
</bean>
<bean
id=
"spam"
class=
"java.lang.String"
>
<constructor-arg
value=
"${spam}"
/>
</bean>
</beans>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录