Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
961f42bd
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,发现更多精彩内容 >>
提交
961f42bd
编写于
1月 15, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduced "spring.getenv.ignore" system property for preventing System.getenv calls
Issue: SPR-11297
上级
ab15ed2a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
21 deletion
+39
-21
spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java
...k/beans/factory/config/PropertyPlaceholderConfigurer.java
+4
-2
spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java
...ava/org/springframework/core/env/AbstractEnvironment.java
+35
-19
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPlaceholderConfigurer.java
浏览文件 @
961f42bd
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
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 java.util.Set;
import
org.springframework.beans.BeansException
;
import
org.springframework.core.Constants
;
import
org.springframework.core.env.AbstractEnvironment
;
import
org.springframework.util.PropertyPlaceholderHelper
;
import
org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver
;
import
org.springframework.util.StringValueResolver
;
...
...
@@ -82,7 +83,8 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport
private
int
systemPropertiesMode
=
SYSTEM_PROPERTIES_MODE_FALLBACK
;
private
boolean
searchSystemEnvironment
=
true
;
private
boolean
searchSystemEnvironment
=
!
"true"
.
equalsIgnoreCase
(
System
.
getProperty
(
AbstractEnvironment
.
IGNORE_GETENV_PROPERTY_NAME
));
/**
...
...
spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java
浏览文件 @
961f42bd
...
...
@@ -52,6 +52,18 @@ import static org.springframework.util.StringUtils.*;
*/
public
abstract
class
AbstractEnvironment
implements
ConfigurableEnvironment
{
/**
* System property that instructs Spring to ignore system environment variables,
* i.e. to never attempt to retrieve such a variable via {@link System#getenv()}.
* <p>The default is "false", falling back to system environment variable checks if a
* Spring environment property (e.g. a placeholder in a configuration String) isn't
* resolvable otherwise. Consider switching this flag to "true" if you experience
* log warnings from {@code getenv} calls coming from Spring, e.g. on WebSphere
* with strict SecurityManager settings and AccessControlExceptions warnings.
*/
public
static
final
String
IGNORE_GETENV_PROPERTY_NAME
=
"spring.getenv.ignore"
;
/**
* Name of property to set to specify active profiles: {@value}. Value may be comma
* delimited.
...
...
@@ -168,8 +180,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
* {@code remove}, or {@code replace} methods exposed by {@link MutablePropertySources}
* in order to create the exact arrangement of property sources desired.
*
* <p>The base implementation in {@link AbstractEnvironment#customizePropertySources}
* registers no property sources.
* <p>The base implementation registers no property sources.
*
* <p>Note that clients of any {@link ConfigurableEnvironment} may further customize
* property sources via the {@link #getPropertySources()} accessor, typically within
...
...
@@ -229,7 +240,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
*/
protected
Set
<
String
>
doGetActiveProfiles
()
{
if
(
this
.
activeProfiles
.
isEmpty
())
{
String
profiles
=
this
.
getProperty
(
ACTIVE_PROFILES_PROPERTY_NAME
);
String
profiles
=
getProperty
(
ACTIVE_PROFILES_PROPERTY_NAME
);
if
(
StringUtils
.
hasText
(
profiles
))
{
setActiveProfiles
(
commaDelimitedListToStringArray
(
trimAllWhitespace
(
profiles
)));
}
...
...
@@ -277,7 +288,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
*/
protected
Set
<
String
>
doGetDefaultProfiles
()
{
if
(
this
.
defaultProfiles
.
equals
(
getReservedDefaultProfiles
()))
{
String
profiles
=
this
.
getProperty
(
DEFAULT_PROFILES_PROPERTY_NAME
);
String
profiles
=
getProperty
(
DEFAULT_PROFILES_PROPERTY_NAME
);
if
(
StringUtils
.
hasText
(
profiles
))
{
setDefaultProfiles
(
commaDelimitedListToStringArray
(
trimAllWhitespace
(
profiles
)));
}
...
...
@@ -356,12 +367,22 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
@Override
@SuppressWarnings
(
"unchecked"
)
public
Map
<
String
,
Object
>
getSystemEnvironment
()
{
Map
<
String
,
?>
systemEnvironment
;
try
{
systemEnvironment
=
System
.
getenv
();
if
(
"true"
.
equalsIgnoreCase
(
System
.
getProperty
(
IGNORE_GETENV_PROPERTY_NAME
)))
{
return
Collections
.
emptyMap
();
}
}
catch
(
Throwable
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Could not obtain system property '"
+
IGNORE_GETENV_PROPERTY_NAME
+
"': "
+
ex
);
}
}
try
{
return
(
Map
)
System
.
getenv
();
}
catch
(
AccessControlException
ex
)
{
systemEnvironment
=
new
ReadOnlySystemAttributesMap
()
{
return
(
Map
)
new
ReadOnlySystemAttributesMap
()
{
@Override
protected
String
getSystemAttribute
(
String
variableName
)
{
try
{
...
...
@@ -369,9 +390,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
catch
(
AccessControlException
ex
)
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
format
(
"Caught AccessControlException when "
+
"accessing system environment variable [%s]; its "
+
"value will be returned [null]. Reason: %s"
,
logger
.
info
(
format
(
"Caught AccessControlException when accessing system "
+
"environment variable [%s]; its value will be returned [null]. Reason: %s"
,
variableName
,
ex
.
getMessage
()));
}
return
null
;
...
...
@@ -379,18 +399,16 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
};
}
return
(
Map
<
String
,
Object
>)
systemEnvironment
;
}
@Override
@SuppressWarnings
(
{
"unchecked"
,
"rawtypes"
}
)
@SuppressWarnings
(
"unchecked"
)
public
Map
<
String
,
Object
>
getSystemProperties
()
{
Map
systemProperties
;
try
{
systemProperties
=
System
.
getProperties
();
return
(
Map
)
System
.
getProperties
();
}
catch
(
AccessControlException
ex
)
{
systemProperties
=
new
ReadOnlySystemAttributesMap
()
{
return
(
Map
)
new
ReadOnlySystemAttributesMap
()
{
@Override
protected
String
getSystemAttribute
(
String
propertyName
)
{
try
{
...
...
@@ -398,9 +416,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
catch
(
AccessControlException
ex
)
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
format
(
"Caught AccessControlException when "
+
"accessing system property [%s]; its value will be "
+
"returned [null]. Reason: %s"
,
logger
.
info
(
format
(
"Caught AccessControlException when accessing system "
+
"property [%s]; its value will be returned [null]. Reason: %s"
,
propertyName
,
ex
.
getMessage
()));
}
return
null
;
...
...
@@ -408,7 +425,6 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
};
}
return
systemProperties
;
}
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录