Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
16325c2e
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 搜索 >>
提交
16325c2e
编写于
9月 20, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
65cc57da
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
186 addition
and
171 deletion
+186
-171
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
...ramework/context/annotation/ConfigurationClassParser.java
+1
-1
spring-context/src/main/java/org/springframework/jndi/JndiPropertySource.java
...ain/java/org/springframework/jndi/JndiPropertySource.java
+10
-6
spring-context/src/test/java/org/springframework/context/support/EnvironmentSecurityManagerIntegrationTests.java
...t/support/EnvironmentSecurityManagerIntegrationTests.java
+16
-13
spring-context/src/test/java/org/springframework/jndi/SimpleNamingContextTests.java
...va/org/springframework/jndi/SimpleNamingContextTests.java
+37
-36
spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java
...framework/tests/mock/jndi/SimpleNamingContextBuilder.java
+6
-11
spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java
...ava/org/springframework/core/env/AbstractEnvironment.java
+43
-37
spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java
...rg/springframework/core/env/AbstractPropertyResolver.java
+54
-43
spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java
...g/springframework/core/env/CommandLinePropertySource.java
+2
-4
spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java
...pringframework/core/env/ConfigurablePropertyResolver.java
+14
-13
spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java
...springframework/mock/jndi/SimpleNamingContextBuilder.java
+3
-7
未找到文件。
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
浏览文件 @
16325c2e
...
...
@@ -375,7 +375,7 @@ class ConfigurationClassParser {
propertySources
.
addLast
(
propertySource
);
}
else
{
String
firstProcessed
=
this
.
propertySourceNames
.
get
(
this
.
propertySourceNames
.
size
()
-
1
);
String
firstProcessed
=
this
.
propertySourceNames
.
get
(
this
.
propertySourceNames
.
size
()
-
1
);
propertySources
.
addBefore
(
firstProcessed
,
propertySource
);
}
}
...
...
spring-context/src/main/java/org/springframework/jndi/JndiPropertySource.java
浏览文件 @
16325c2e
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -69,9 +69,9 @@ public class JndiPropertySource extends PropertySource<JndiLocatorDelegate> {
super
(
name
,
jndiLocator
);
}
/**
* {@inheritDoc}
* <p>This implementation looks up and returns the value associated with the given
* This implementation looks up and returns the value associated with the given
* name from the underlying {@link JndiLocatorDelegate}. If a {@link NamingException}
* is thrown during the call to {@link JndiLocatorDelegate#lookup(String)}, returns
* {@code null} and issues a DEBUG-level log statement with the exception message.
...
...
@@ -80,12 +80,16 @@ public class JndiPropertySource extends PropertySource<JndiLocatorDelegate> {
public
Object
getProperty
(
String
name
)
{
try
{
Object
value
=
this
.
source
.
lookup
(
name
);
logger
.
debug
(
"JNDI lookup for name ["
+
name
+
"] returned: ["
+
value
+
"]"
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"JNDI lookup for name ["
+
name
+
"] returned: ["
+
value
+
"]"
);
}
return
value
;
}
catch
(
NamingException
ex
)
{
logger
.
debug
(
"JNDI lookup for name ["
+
name
+
"] threw NamingException "
+
"with message: "
+
ex
.
getMessage
()
+
". Returning null."
);
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"JNDI lookup for name ["
+
name
+
"] threw NamingException "
+
"with message: "
+
ex
.
getMessage
()
+
". Returning null."
);
}
return
null
;
}
}
...
...
spring-context/src/test/java/org/springframework/context/support/EnvironmentSecurityManagerIntegrationTests.java
浏览文件 @
16325c2e
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -16,10 +16,6 @@
package
org.springframework.context.support
;
import
static
java
.
lang
.
String
.
format
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
java.security.AccessControlException
;
import
java.security.Permission
;
import
java.util.Map
;
...
...
@@ -35,6 +31,10 @@ import org.springframework.core.env.AbstractEnvironment;
import
org.springframework.core.env.StandardEnvironmentTests
;
import
org.springframework.stereotype.Component
;
import
static
java
.
lang
.
String
.
format
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* Tests integration between Environment and SecurityManagers. See SPR-9970.
*
...
...
@@ -43,8 +43,10 @@ import org.springframework.stereotype.Component;
public
class
EnvironmentSecurityManagerIntegrationTests
{
private
SecurityManager
originalSecurityManager
;
private
Map
<
String
,
String
>
env
;
@Before
public
void
setUp
()
{
originalSecurityManager
=
System
.
getSecurityManager
();
...
...
@@ -58,16 +60,16 @@ public class EnvironmentSecurityManagerIntegrationTests {
System
.
setSecurityManager
(
originalSecurityManager
);
}
@Test
public
void
securityManagerDisallowsAccessToSystemEnvironmentButAllowsAccessToIndividualKeys
()
{
SecurityManager
securityManager
=
new
SecurityManager
()
{
@Override
public
void
checkPermission
(
Permission
perm
)
{
//
d
isallowing access to System#getenv means that our
//
D
isallowing access to System#getenv means that our
// ReadOnlySystemAttributesMap will come into play.
if
(
"getenv.*"
.
equals
(
perm
.
getName
()))
{
throw
new
AccessControlException
(
"Accessing the system environment is disallowed"
);
throw
new
AccessControlException
(
"Accessing the system environment is disallowed"
);
}
}
};
...
...
@@ -84,18 +86,17 @@ public class EnvironmentSecurityManagerIntegrationTests {
SecurityManager
securityManager
=
new
SecurityManager
()
{
@Override
public
void
checkPermission
(
Permission
perm
)
{
//
d
isallowing access to System#getenv means that our
//
D
isallowing access to System#getenv means that our
// ReadOnlySystemAttributesMap will come into play.
if
(
"getenv.*"
.
equals
(
perm
.
getName
()))
{
throw
new
AccessControlException
(
"Accessing the system environment is disallowed"
);
throw
new
AccessControlException
(
"Accessing the system environment is disallowed"
);
}
//
d
isallowing access to the spring.profiles.active property means that
//
D
isallowing access to the spring.profiles.active property means that
// the BeanDefinitionReader won't be able to determine which profiles are
// active. We should see an INFO-level message in the console about this
// and as a result, any components marked with a non-default profile will
// be ignored.
if
((
"getenv."
+
AbstractEnvironment
.
ACTIVE_PROFILES_PROPERTY_NAME
).
equals
(
perm
.
getName
()))
{
if
((
"getenv."
+
AbstractEnvironment
.
ACTIVE_PROFILES_PROPERTY_NAME
).
equals
(
perm
.
getName
()))
{
throw
new
AccessControlException
(
format
(
"Accessing system environment variable [%s] is disallowed"
,
AbstractEnvironment
.
ACTIVE_PROFILES_PROPERTY_NAME
));
...
...
@@ -110,8 +111,10 @@ public class EnvironmentSecurityManagerIntegrationTests {
assertThat
(
bf
.
containsBean
(
"c1"
),
is
(
false
));
}
@Component
(
"c1"
)
@Profile
(
"p1"
)
static
class
C1
{
}
}
spring-context/src/test/java/org/springframework/jndi/SimpleNamingContextTests.java
浏览文件 @
16325c2e
/*
* Copyright 2002-201
3
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -214,52 +214,53 @@ public class SimpleNamingContextTests {
assertEquals
(
ctx
.
lookup
(
name
),
o2
);
}
}
class
StubDataSource
implements
DataSource
{
static
class
StubDataSource
implements
DataSource
{
@Override
public
Connection
getConnection
()
throws
SQLException
{
return
null
;
}
@Override
public
Connection
getConnection
()
throws
SQLException
{
return
null
;
}
@Override
public
Connection
getConnection
(
String
username
,
String
password
)
throws
SQLException
{
return
null
;
}
@Override
public
Connection
getConnection
(
String
username
,
String
password
)
throws
SQLException
{
return
null
;
}
@Override
public
PrintWriter
getLogWriter
()
throws
SQLException
{
return
null
;
}
@Override
public
PrintWriter
getLogWriter
()
throws
SQLException
{
return
null
;
}
@Override
public
int
getLoginTimeout
()
throws
SQLException
{
return
0
;
}
@Override
public
int
getLoginTimeout
()
throws
SQLException
{
return
0
;
}
@Override
public
void
setLogWriter
(
PrintWriter
arg0
)
throws
SQLException
{
@Override
public
void
setLogWriter
(
PrintWriter
arg0
)
throws
SQLException
{
}
}
@Override
public
void
setLoginTimeout
(
int
arg0
)
throws
SQLException
{
@Override
public
void
setLoginTimeout
(
int
arg0
)
throws
SQLException
{
}
}
@Override
public
boolean
isWrapperFor
(
Class
<?>
arg0
)
throws
SQLException
{
return
false
;
}
@Override
public
boolean
isWrapperFor
(
Class
<?>
arg0
)
throws
SQLException
{
return
false
;
}
@Override
public
<
T
>
T
unwrap
(
Class
<
T
>
arg0
)
throws
SQLException
{
return
null
;
}
@Override
public
<
T
>
T
unwrap
(
Class
<
T
>
arg0
)
throws
SQLException
{
return
null
;
}
@Override
public
Logger
getParentLogger
()
{
return
null
;
@Override
public
Logger
getParentLogger
()
{
return
null
;
}
}
}
spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java
浏览文件 @
16325c2e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -17,7 +17,6 @@
package
org.springframework.tests.mock.jndi
;
import
java.util.Hashtable
;
import
javax.naming.Context
;
import
javax.naming.NamingException
;
import
javax.naming.spi.InitialContextFactory
;
...
...
@@ -40,9 +39,9 @@ import org.springframework.util.ClassUtils;
*
* <p>There are various choices for DataSource implementations:
* <ul>
* <li>
SingleConnectionDataSource (using the same Connection for all getConnection calls);
* <li>
DriverManagerDataSource (creating a new Connection on each getConnection call);
* <li>Apache's Jakarta Commons DBCP offers
BasicDataSource (a real pool).
* <li>
{@code SingleConnectionDataSource} (using the same Connection for all getConnection calls)
* <li>
{@code DriverManagerDataSource} (creating a new Connection on each getConnection call)
* <li>Apache's Jakarta Commons DBCP offers
{@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
* </ul>
*
* <p>Typical usage in bootstrap code:
...
...
@@ -77,7 +76,6 @@ import org.springframework.util.ClassUtils;
* @see SimpleNamingContext
* @see org.springframework.jdbc.datasource.SingleConnectionDataSource
* @see org.springframework.jdbc.datasource.DriverManagerDataSource
* @see org.apache.commons.dbcp.BasicDataSource
*/
public
class
SimpleNamingContextBuilder
implements
InitialContextFactoryBuilder
{
...
...
@@ -197,7 +195,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
if
(
activated
==
null
&&
environment
!=
null
)
{
Object
icf
=
environment
.
get
(
Context
.
INITIAL_CONTEXT_FACTORY
);
if
(
icf
!=
null
)
{
Class
<?>
icfClass
=
null
;
Class
<?>
icfClass
;
if
(
icf
instanceof
Class
)
{
icfClass
=
(
Class
<?>)
icf
;
}
...
...
@@ -216,10 +214,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
return
(
InitialContextFactory
)
icfClass
.
newInstance
();
}
catch
(
Throwable
ex
)
{
IllegalStateException
ise
=
new
IllegalStateException
(
"Cannot instantiate specified InitialContextFactory: "
+
icf
);
ise
.
initCause
(
ex
);
throw
ise
;
throw
new
IllegalStateException
(
"Cannot instantiate specified InitialContextFactory: "
+
icf
,
ex
);
}
}
}
...
...
spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java
浏览文件 @
16325c2e
...
...
@@ -295,7 +295,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
}
/**
* {@inheritDoc}
* Specify the set of profiles to be made active by default if no other profiles
* are explicitly made active through {@link #setActiveProfiles}.
* <p>Calling this method removes overrides any reserved default profiles
* that may have been added during construction of the environment.
* @see #AbstractEnvironment()
...
...
@@ -456,93 +457,98 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
//---------------------------------------------------------------------
@Override
public
boolean
containsProperty
(
String
key
)
{
return
this
.
propertyResolver
.
containsProperty
(
key
);
public
ConfigurableConversionService
getConversionService
(
)
{
return
this
.
propertyResolver
.
getConversionService
(
);
}
@Override
public
String
getProperty
(
String
key
)
{
return
this
.
propertyResolver
.
getProperty
(
key
);
public
void
setConversionService
(
ConfigurableConversionService
conversionService
)
{
this
.
propertyResolver
.
setConversionService
(
conversionService
);
}
@Override
public
String
getProperty
(
String
key
,
String
defaultValue
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
defaultValue
);
public
void
setPlaceholderPrefix
(
String
placeholderPrefix
)
{
this
.
propertyResolver
.
setPlaceholderPrefix
(
placeholderPrefix
);
}
@Override
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
targetType
);
public
void
setPlaceholderSuffix
(
String
placeholderSuffix
)
{
this
.
propertyResolver
.
setPlaceholderSuffix
(
placeholderSuffix
);
}
@Override
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
,
T
defaultValue
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
targetType
,
defaultValue
);
public
void
setValueSeparator
(
String
valueSeparator
)
{
this
.
propertyResolver
.
setValueSeparator
(
valueSeparator
);
}
@Override
public
<
T
>
Class
<
T
>
getPropertyAsClass
(
String
key
,
Class
<
T
>
targetType
)
{
return
this
.
propertyResolver
.
getPropertyAsClass
(
key
,
targetType
);
public
void
setIgnoreUnresolvableNestedPlaceholders
(
boolean
ignoreUnresolvableNestedPlaceholders
)
{
this
.
propertyResolver
.
setIgnoreUnresolvableNestedPlaceholders
(
ignoreUnresolvableNestedPlaceholders
);
}
@Override
public
String
getRequiredProperty
(
String
key
)
throws
IllegalStateException
{
return
this
.
propertyResolver
.
getRequiredProperty
(
key
);
public
void
setRequiredProperties
(
String
...
requiredProperties
)
{
this
.
propertyResolver
.
setRequiredProperties
(
requiredProperties
);
}
@Override
public
<
T
>
T
getRequiredProperty
(
String
key
,
Class
<
T
>
targetType
)
throws
IllegalState
Exception
{
return
this
.
propertyResolver
.
getRequiredProperty
(
key
,
targetType
);
public
void
validateRequiredProperties
()
throws
MissingRequiredProperties
Exception
{
this
.
propertyResolver
.
validateRequiredProperties
(
);
}
//---------------------------------------------------------------------
// Implementation of PropertyResolver interface
//---------------------------------------------------------------------
@Override
public
void
setRequiredProperties
(
String
...
requiredProperties
)
{
this
.
propertyResolver
.
setRequiredProperties
(
requiredProperties
);
public
boolean
containsProperty
(
String
key
)
{
return
this
.
propertyResolver
.
containsProperty
(
key
);
}
@Override
public
void
validateRequiredProperties
()
throws
MissingRequiredPropertiesException
{
this
.
propertyResolver
.
validateRequiredProperties
(
);
public
String
getProperty
(
String
key
)
{
return
this
.
propertyResolver
.
getProperty
(
key
);
}
@Override
public
String
resolvePlaceholders
(
String
text
)
{
return
this
.
propertyResolver
.
resolvePlaceholders
(
text
);
public
String
getProperty
(
String
key
,
String
defaultValue
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
defaultValue
);
}
@Override
public
String
resolveRequiredPlaceholders
(
String
text
)
throws
IllegalArgumentException
{
return
this
.
propertyResolver
.
resolveRequiredPlaceholders
(
text
);
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
targetType
);
}
@Override
public
void
setIgnoreUnresolvableNestedPlaceholders
(
boolean
ignoreUnresolvableNestedPlaceholders
)
{
this
.
propertyResolver
.
setIgnoreUnresolvableNestedPlaceholders
(
ignoreUnresolvableNestedPlaceholders
);
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
,
T
defaultValue
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
targetType
,
defaultValue
);
}
@Override
public
void
setConversionService
(
ConfigurableConversionService
conversionServic
e
)
{
this
.
propertyResolver
.
setConversionService
(
conversionServic
e
);
public
<
T
>
Class
<
T
>
getPropertyAsClass
(
String
key
,
Class
<
T
>
targetTyp
e
)
{
return
this
.
propertyResolver
.
getPropertyAsClass
(
key
,
targetTyp
e
);
}
@Override
public
ConfigurableConversionService
getConversionService
()
{
return
this
.
propertyResolver
.
get
ConversionService
(
);
public
String
getRequiredProperty
(
String
key
)
throws
IllegalStateException
{
return
this
.
propertyResolver
.
get
RequiredProperty
(
key
);
}
@Override
public
void
setPlaceholderPrefix
(
String
placeholderPrefix
)
{
this
.
propertyResolver
.
setPlaceholderPrefix
(
placeholderPrefix
);
public
<
T
>
T
getRequiredProperty
(
String
key
,
Class
<
T
>
targetType
)
throws
IllegalStateException
{
return
this
.
propertyResolver
.
getRequiredProperty
(
key
,
targetType
);
}
@Override
public
void
setPlaceholderSuffix
(
String
placeholderSuffix
)
{
this
.
propertyResolver
.
setPlaceholderSuffix
(
placeholderSuffix
);
public
String
resolvePlaceholders
(
String
text
)
{
return
this
.
propertyResolver
.
resolvePlaceholders
(
text
);
}
@Override
public
void
setValueSeparator
(
String
valueSeparator
)
{
this
.
propertyResolver
.
setValueSeparator
(
valueSeparator
);
public
String
resolveRequiredPlaceholders
(
String
text
)
throws
IllegalArgumentException
{
return
this
.
propertyResolver
.
resolveRequiredPlaceholders
(
text
);
}
...
...
spring-core/src/main/java/org/springframework/core/env/AbstractPropertyResolver.java
浏览文件 @
16325c2e
...
...
@@ -65,16 +65,50 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
this
.
conversionService
=
conversionService
;
}
/**
* Set the prefix that placeholders replaced by this resolver must begin with.
* <p>The default is "${".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_PREFIX
*/
@Override
public
String
getProperty
(
String
key
,
String
defaultValue
)
{
String
value
=
getProperty
(
key
);
return
(
value
!=
null
?
value
:
defaultValue
);
public
void
setPlaceholderPrefix
(
String
placeholderPrefix
)
{
this
.
placeholderPrefix
=
placeholderPrefix
;
}
/**
* Set the suffix that placeholders replaced by this resolver must end with.
* <p>The default is "}".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_SUFFIX
*/
@Override
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
,
T
defaultValue
)
{
T
value
=
getProperty
(
key
,
targetType
);
return
(
value
!=
null
?
value
:
defaultValue
);
public
void
setPlaceholderSuffix
(
String
placeholderSuffix
)
{
this
.
placeholderSuffix
=
placeholderSuffix
;
}
/**
* Specify the separating character between the placeholders replaced by this
* resolver and their associated default value, or {@code null} if no such
* special character should be processed as a value separator.
* <p>The default is ":".
* @see org.springframework.util.SystemPropertyUtils#VALUE_SEPARATOR
*/
@Override
public
void
setValueSeparator
(
String
valueSeparator
)
{
this
.
valueSeparator
=
valueSeparator
;
}
/**
* Set whether to throw an exception when encountering an unresolvable placeholder
* nested within the value of a given property. A {@code false} value indicates strict
* resolution, i.e. that an exception will be thrown. A {@code true} value indicates
* that unresolvable nested placeholders should be passed through in their unresolved
* ${...} form.
* <p>The default is {@code false}.
* @since 3.2
*/
@Override
public
void
setIgnoreUnresolvableNestedPlaceholders
(
boolean
ignoreUnresolvableNestedPlaceholders
)
{
this
.
ignoreUnresolvableNestedPlaceholders
=
ignoreUnresolvableNestedPlaceholders
;
}
@Override
...
...
@@ -97,6 +131,19 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
}
}
@Override
public
String
getProperty
(
String
key
,
String
defaultValue
)
{
String
value
=
getProperty
(
key
);
return
(
value
!=
null
?
value
:
defaultValue
);
}
@Override
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
,
T
defaultValue
)
{
T
value
=
getProperty
(
key
,
targetType
);
return
(
value
!=
null
?
value
:
defaultValue
);
}
@Override
public
String
getRequiredProperty
(
String
key
)
throws
IllegalStateException
{
String
value
=
getProperty
(
key
);
...
...
@@ -115,33 +162,6 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
return
value
;
}
/**
* {@inheritDoc} The default is "${".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_PREFIX
*/
@Override
public
void
setPlaceholderPrefix
(
String
placeholderPrefix
)
{
this
.
placeholderPrefix
=
placeholderPrefix
;
}
/**
* {@inheritDoc} The default is "}".
* @see org.springframework.util.SystemPropertyUtils#PLACEHOLDER_SUFFIX
*/
@Override
public
void
setPlaceholderSuffix
(
String
placeholderSuffix
)
{
this
.
placeholderSuffix
=
placeholderSuffix
;
}
/**
* {@inheritDoc} The default is ":".
* @see org.springframework.util.SystemPropertyUtils#VALUE_SEPARATOR
*/
@Override
public
void
setValueSeparator
(
String
valueSeparator
)
{
this
.
valueSeparator
=
valueSeparator
;
}
@Override
public
String
resolvePlaceholders
(
String
text
)
{
if
(
this
.
nonStrictHelper
==
null
)
{
...
...
@@ -158,16 +178,6 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
return
doResolvePlaceholders
(
text
,
this
.
strictHelper
);
}
/**
* {@inheritDoc}
* <p>The default value for this implementation is {@code false}.
* @since 3.2
*/
@Override
public
void
setIgnoreUnresolvableNestedPlaceholders
(
boolean
ignoreUnresolvableNestedPlaceholders
)
{
this
.
ignoreUnresolvableNestedPlaceholders
=
ignoreUnresolvableNestedPlaceholders
;
}
/**
* Resolve placeholders within the given string, deferring to the value of
* {@link #setIgnoreUnresolvableNestedPlaceholders} to determine whether any
...
...
@@ -199,6 +209,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe
});
}
/**
* Retrieve the specified property as a raw String,
* i.e. without resolution of nested placeholders.
...
...
spring-core/src/main/java/org/springframework/core/env/CommandLinePropertySource.java
浏览文件 @
16325c2e
...
...
@@ -223,8 +223,7 @@ public abstract class CommandLinePropertySource<T> extends EnumerablePropertySou
}
/**
* Return whether this {@code PropertySource} contains a property with the given name.
* <p>This implementation first checks to see if the name specified is the special
* This implementation first checks to see if the name specified is the special
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
* and if so delegates to the abstract {@link #getNonOptionArgs()} method
* checking to see whether it returns an empty collection. Otherwise delegates to and
...
...
@@ -239,8 +238,7 @@ public abstract class CommandLinePropertySource<T> extends EnumerablePropertySou
}
/**
* {@inheritDoc}
* <p>This implementation first checks to see if the name specified is the special
* This implementation first checks to see if the name specified is the special
* {@linkplain #setNonOptionArgsPropertyName(String) "non-option arguments" property},
* and if so delegates to the abstract {@link #getNonOptionArgs()} method. If so
* and the collection of non-option arguments is empty, this method returns {@code
...
...
spring-core/src/main/java/org/springframework/core/env/ConfigurablePropertyResolver.java
浏览文件 @
16325c2e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -73,6 +73,19 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
*/
void
setValueSeparator
(
String
valueSeparator
);
/**
* Set whether to throw an exception when encountering an unresolvable placeholder
* nested within the value of a given property. A {@code false} value indicates strict
* resolution, i.e. that an exception will be thrown. A {@code true} value indicates
* that unresolvable nested placeholders should be passed through in their unresolved
* ${...} form.
* <p>Implementations of {@link #getProperty(String)} and its variants must inspect
* the value set here to determine correct behavior when property values contain
* unresolvable placeholders.
* @since 3.2
*/
void
setIgnoreUnresolvableNestedPlaceholders
(
boolean
ignoreUnresolvableNestedPlaceholders
);
/**
* Specify which properties must be present, to be verified by
* {@link #validateRequiredProperties()}.
...
...
@@ -88,16 +101,4 @@ public interface ConfigurablePropertyResolver extends PropertyResolver {
*/
void
validateRequiredProperties
()
throws
MissingRequiredPropertiesException
;
/**
* Set whether to throw an exception when encountering an unresolvable placeholder
* nested within the value of a given property. A {@code false} value indicates strict
* resolution, i.e. that an exception will be thrown. A {@code true} value indicates
* that unresolvable nested placeholders should be passed through in their unresolved
* ${...} form.
* <p>Implementations of {@link #getProperty(String)} and its variants must inspect
* the value set here to determine correct behavior when property values contain
* unresolvable placeholders.
* @since 3.2
*/
void
setIgnoreUnresolvableNestedPlaceholders
(
boolean
ignoreUnresolvableNestedPlaceholders
);
}
spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java
浏览文件 @
16325c2e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
4
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.
...
...
@@ -17,7 +17,6 @@
package
org.springframework.mock.jndi
;
import
java.util.Hashtable
;
import
javax.naming.Context
;
import
javax.naming.NamingException
;
import
javax.naming.spi.InitialContextFactory
;
...
...
@@ -196,7 +195,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
if
(
activated
==
null
&&
environment
!=
null
)
{
Object
icf
=
environment
.
get
(
Context
.
INITIAL_CONTEXT_FACTORY
);
if
(
icf
!=
null
)
{
Class
<?>
icfClass
=
null
;
Class
<?>
icfClass
;
if
(
icf
instanceof
Class
)
{
icfClass
=
(
Class
<?>)
icf
;
}
...
...
@@ -215,10 +214,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
return
(
InitialContextFactory
)
icfClass
.
newInstance
();
}
catch
(
Throwable
ex
)
{
IllegalStateException
ise
=
new
IllegalStateException
(
"Cannot instantiate specified InitialContextFactory: "
+
icf
);
ise
.
initCause
(
ex
);
throw
ise
;
throw
new
IllegalStateException
(
"Cannot instantiate specified InitialContextFactory: "
+
icf
,
ex
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录