Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
7e015785
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,发现更多精彩内容 >>
提交
7e015785
编写于
5月 15, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid unnecessary creation of default StandardEnvironment instances
Issue: SPR-10568
上级
7cddeb6d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
132 addition
and
114 deletion
+132
-114
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java
...k/beans/factory/support/AbstractBeanDefinitionReader.java
+3
-3
spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java
...pringframework/beans/support/ResourceEditorRegistrar.java
+5
-2
spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java
...notation/ClassPathScanningCandidateComponentProvider.java
+11
-2
spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java
...ava/org/springframework/core/env/AbstractEnvironment.java
+2
-2
spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java
...ngframework/core/env/PropertySourcesPropertyResolver.java
+64
-64
spring-core/src/main/java/org/springframework/core/io/ResourceEditor.java
...main/java/org/springframework/core/io/ResourceEditor.java
+21
-21
spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java
...ramework/core/io/support/ResourceArrayPropertyEditor.java
+26
-20
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinitionReader.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -54,7 +54,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
...
@@ -54,7 +54,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
private
ClassLoader
beanClassLoader
;
private
ClassLoader
beanClassLoader
;
private
Environment
environment
=
new
StandardEnvironment
()
;
private
Environment
environment
;
private
BeanNameGenerator
beanNameGenerator
=
new
DefaultBeanNameGenerator
();
private
BeanNameGenerator
beanNameGenerator
=
new
DefaultBeanNameGenerator
();
...
@@ -90,7 +90,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
...
@@ -90,7 +90,7 @@ public abstract class AbstractBeanDefinitionReader implements EnvironmentCapable
// Inherit Environment if possible
// Inherit Environment if possible
if
(
this
.
registry
instanceof
EnvironmentCapable
)
{
if
(
this
.
registry
instanceof
EnvironmentCapable
)
{
this
.
environment
=
((
EnvironmentCapable
)
this
.
registry
).
getEnvironment
();
this
.
environment
=
((
EnvironmentCapable
)
this
.
registry
).
getEnvironment
();
}
}
else
{
else
{
this
.
environment
=
new
StandardEnvironment
();
this
.
environment
=
new
StandardEnvironment
();
...
...
spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -78,9 +78,12 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
...
@@ -78,9 +78,12 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
}
}
/**
/**
* Create a new ResourceEditorRegistrar for the given ResourceLoader
* Create a new ResourceEditorRegistrar for the given {@link ResourceLoader}
* and {@link PropertyResolver}.
* @param resourceLoader the ResourceLoader (or ResourcePatternResolver)
* @param resourceLoader the ResourceLoader (or ResourcePatternResolver)
* to create editors for (usually an ApplicationContext)
* to create editors for (usually an ApplicationContext)
* @param propertyResolver the PropertyResolver (usually an Environment)
* @see org.springframework.core.env.Environment
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.core.io.support.ResourcePatternResolver
* @see org.springframework.context.ApplicationContext
* @see org.springframework.context.ApplicationContext
*/
*/
...
...
spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -90,7 +90,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
...
@@ -90,7 +90,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
/**
/**
* Create a ClassPathScanningCandidateComponentProvider.
* Create a ClassPathScanningCandidateComponentProvider
with a {@link StandardEnvironment}
.
* @param useDefaultFilters whether to register the default filters for the
* @param useDefaultFilters whether to register the default filters for the
* {@link Component @Component}, {@link Repository @Repository},
* {@link Component @Component}, {@link Repository @Repository},
* {@link Service @Service}, and {@link Controller @Controller}
* {@link Service @Service}, and {@link Controller @Controller}
...
@@ -101,6 +101,15 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
...
@@ -101,6 +101,15 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
this
(
useDefaultFilters
,
new
StandardEnvironment
());
this
(
useDefaultFilters
,
new
StandardEnvironment
());
}
}
/**
* Create a ClassPathScanningCandidateComponentProvider with the given {@link Environment}.
* @param useDefaultFilters whether to register the default filters for the
* {@link Component @Component}, {@link Repository @Repository},
* {@link Service @Service}, and {@link Controller @Controller}
* stereotype annotations
* @param environment the Environment to use
* @see #registerDefaultFilters()
*/
public
ClassPathScanningCandidateComponentProvider
(
boolean
useDefaultFilters
,
Environment
environment
)
{
public
ClassPathScanningCandidateComponentProvider
(
boolean
useDefaultFilters
,
Environment
environment
)
{
if
(
useDefaultFilters
)
{
if
(
useDefaultFilters
)
{
registerDefaultFilters
();
registerDefaultFilters
();
...
...
spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -452,7 +452,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
...
@@ -452,7 +452,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
@Override
@Override
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
,
T
defaultValue
)
{
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetType
,
T
defaultValue
)
{
return
this
.
propertyResolver
.
getProperty
(
key
,
targetType
,
defaultValue
);
return
this
.
propertyResolver
.
getProperty
(
key
,
targetType
,
defaultValue
);
}
;
}
@Override
@Override
public
<
T
>
Class
<
T
>
getPropertyAsClass
(
String
key
,
Class
<
T
>
targetType
)
{
public
<
T
>
Class
<
T
>
getPropertyAsClass
(
String
key
,
Class
<
T
>
targetType
)
{
...
...
spring-core/src/main/java/org/springframework/core/env/PropertySourcesPropertyResolver.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -16,8 +16,6 @@
...
@@ -16,8 +16,6 @@
package
org.springframework.core.env
;
package
org.springframework.core.env
;
import
static
java
.
lang
.
String
.
format
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.core.convert.ConversionException
;
import
org.springframework.util.ClassUtils
;
import
org.springframework.util.ClassUtils
;
...
@@ -35,6 +33,7 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
...
@@ -35,6 +33,7 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
private
final
PropertySources
propertySources
;
private
final
PropertySources
propertySources
;
/**
/**
* Create a new resolver against the given property sources.
* Create a new resolver against the given property sources.
* @param propertySources the set of {@link PropertySource} objects to use
* @param propertySources the set of {@link PropertySource} objects to use
...
@@ -43,11 +42,14 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
...
@@ -43,11 +42,14 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
this
.
propertySources
=
propertySources
;
this
.
propertySources
=
propertySources
;
}
}
@Override
@Override
public
boolean
containsProperty
(
String
key
)
{
public
boolean
containsProperty
(
String
key
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
if
(
this
.
propertySources
!=
null
)
{
if
(
propertySource
.
containsProperty
(
key
))
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
return
true
;
if
(
propertySource
.
containsProperty
(
key
))
{
return
true
;
}
}
}
}
}
return
false
;
return
false
;
...
@@ -55,45 +57,41 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
...
@@ -55,45 +57,41 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
@Override
@Override
public
String
getProperty
(
String
key
)
{
public
String
getProperty
(
String
key
)
{
if
(
logger
.
isTraceEnabled
())
{
return
getProperty
(
key
,
String
.
class
);
logger
.
trace
(
format
(
"getProperty(\"%s\") (implicit targetType [String])"
,
key
));
}
return
this
.
getProperty
(
key
,
String
.
class
);
}
}
@Override
@Override
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetValueType
)
{
public
<
T
>
T
getProperty
(
String
key
,
Class
<
T
>
targetValueType
)
{
boolean
debugEnabled
=
logger
.
isDebugEnabled
();
boolean
debugEnabled
=
logger
.
isDebugEnabled
();
if
(
logger
.
isTraceEnabled
())
{
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
format
(
"getProperty(\"%s\", %s)"
,
key
,
targetValueType
.
getSimpleName
()));
logger
.
trace
(
String
.
format
(
"getProperty(\"%s\", %s)"
,
key
,
targetValueType
.
getSimpleName
()));
}
}
if
(
this
.
propertySources
!=
null
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
if
(
debugEnabled
)
{
logger
.
debug
(
format
(
"Searching for key '%s' in [%s]"
,
key
,
propertySource
.
getName
()));
}
Object
value
;
if
((
value
=
propertySource
.
getProperty
(
key
))
!=
null
)
{
Class
<?>
valueType
=
value
.
getClass
();
if
(
String
.
class
.
equals
(
valueType
))
{
value
=
this
.
resolveNestedPlaceholders
((
String
)
value
);
}
if
(
debugEnabled
)
{
if
(
debugEnabled
)
{
logger
.
debug
(
logger
.
debug
(
String
.
format
(
"Searching for key '%s' in [%s]"
,
key
,
propertySource
.
getName
()));
format
(
"Found key '%s' in [%s] with type [%s] and value '%s'"
,
key
,
propertySource
.
getName
(),
valueType
.
getSimpleName
(),
value
));
}
}
if
(!
this
.
conversionService
.
canConvert
(
valueType
,
targetValueType
))
{
Object
value
;
throw
new
IllegalArgumentException
(
if
((
value
=
propertySource
.
getProperty
(
key
))
!=
null
)
{
format
(
"Cannot convert value [%s] from source type [%s] to target type [%s]"
,
Class
<?>
valueType
=
value
.
getClass
();
value
,
valueType
.
getSimpleName
(),
targetValueType
.
getSimpleName
()));
if
(
String
.
class
.
equals
(
valueType
))
{
value
=
this
.
resolveNestedPlaceholders
((
String
)
value
);
}
if
(
debugEnabled
)
{
logger
.
debug
(
String
.
format
(
"Found key '%s' in [%s] with type [%s] and value '%s'"
,
key
,
propertySource
.
getName
(),
valueType
.
getSimpleName
(),
value
));
}
if
(!
this
.
conversionService
.
canConvert
(
valueType
,
targetValueType
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Cannot convert value [%s] from source type [%s] to target type [%s]"
,
value
,
valueType
.
getSimpleName
(),
targetValueType
.
getSimpleName
()));
}
return
conversionService
.
convert
(
value
,
targetValueType
);
}
}
return
conversionService
.
convert
(
value
,
targetValueType
);
}
}
}
}
if
(
debugEnabled
)
{
if
(
debugEnabled
)
{
logger
.
debug
(
format
(
"Could not find key '%s' in any property source. Returning [null]"
,
key
));
logger
.
debug
(
String
.
format
(
"Could not find key '%s' in any property source. Returning [null]"
,
key
));
}
}
return
null
;
return
null
;
}
}
...
@@ -102,51 +100,52 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
...
@@ -102,51 +100,52 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
public
<
T
>
Class
<
T
>
getPropertyAsClass
(
String
key
,
Class
<
T
>
targetValueType
)
{
public
<
T
>
Class
<
T
>
getPropertyAsClass
(
String
key
,
Class
<
T
>
targetValueType
)
{
boolean
debugEnabled
=
logger
.
isDebugEnabled
();
boolean
debugEnabled
=
logger
.
isDebugEnabled
();
if
(
logger
.
isTraceEnabled
())
{
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
format
(
"getPropertyAsClass(\"%s\", %s)"
,
key
,
targetValueType
.
getSimpleName
()));
logger
.
trace
(
String
.
format
(
"getPropertyAsClass(\"%s\", %s)"
,
key
,
targetValueType
.
getSimpleName
()));
}
}
if
(
this
.
propertySources
!=
null
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
for
(
PropertySource
<?>
propertySource
:
this
.
propertySources
)
{
if
(
debugEnabled
)
{
logger
.
debug
(
format
(
"Searching for key '%s' in [%s]"
,
key
,
propertySource
.
getName
()));
}
Object
value
;
if
((
value
=
propertySource
.
getProperty
(
key
))
!=
null
)
{
if
(
debugEnabled
)
{
if
(
debugEnabled
)
{
logger
.
debug
(
logger
.
debug
(
String
.
format
(
"Searching for key '%s' in [%s]"
,
key
,
propertySource
.
getName
()));
format
(
"Found key '%s' in [%s] with value '%s'"
,
key
,
propertySource
.
getName
(),
value
));
}
}
Object
value
=
propertySource
.
getProperty
(
key
);
Class
<?>
clazz
;
if
(
value
!=
null
)
{
if
(
value
instanceof
String
)
{
if
(
debugEnabled
)
{
try
{
logger
.
debug
(
String
.
format
(
"Found key '%s' in [%s] with value '%s'"
,
key
,
propertySource
.
getName
(),
value
));
clazz
=
ClassUtils
.
forName
((
String
)
value
,
null
);
}
catch
(
Exception
ex
)
{
throw
new
ClassConversionException
((
String
)
value
,
targetValueType
,
ex
);
}
}
Class
<?>
clazz
;
if
(
value
instanceof
String
)
{
try
{
clazz
=
ClassUtils
.
forName
((
String
)
value
,
null
);
}
catch
(
Exception
ex
)
{
throw
new
ClassConversionException
((
String
)
value
,
targetValueType
,
ex
);
}
}
else
if
(
value
instanceof
Class
)
{
clazz
=
(
Class
<?>)
value
;
}
else
{
clazz
=
value
.
getClass
();
}
if
(!
targetValueType
.
isAssignableFrom
(
clazz
))
{
throw
new
ClassConversionException
(
clazz
,
targetValueType
);
}
@SuppressWarnings
(
"unchecked"
)
Class
<
T
>
targetClass
=
(
Class
<
T
>)
clazz
;
return
targetClass
;
}
}
else
if
(
value
instanceof
Class
)
{
clazz
=
(
Class
<?>)
value
;
}
else
{
clazz
=
value
.
getClass
();
}
if
(!
targetValueType
.
isAssignableFrom
(
clazz
))
{
throw
new
ClassConversionException
(
clazz
,
targetValueType
);
}
@SuppressWarnings
(
"unchecked"
)
Class
<
T
>
targetClass
=
(
Class
<
T
>)
clazz
;
return
targetClass
;
}
}
}
}
if
(
debugEnabled
)
{
if
(
debugEnabled
)
{
logger
.
debug
(
format
(
"Could not find key '%s' in any property source. Returning [null]"
,
key
));
logger
.
debug
(
String
.
format
(
"Could not find key '%s' in any property source. Returning [null]"
,
key
));
}
}
return
null
;
return
null
;
}
}
@SuppressWarnings
(
"serial"
)
@SuppressWarnings
(
"serial"
)
static
class
ClassConversionException
extends
ConversionException
{
private
static
class
ClassConversionException
extends
ConversionException
{
public
ClassConversionException
(
Class
<?>
actual
,
Class
<?>
expected
)
{
public
ClassConversionException
(
Class
<?>
actual
,
Class
<?>
expected
)
{
super
(
String
.
format
(
"Actual type %s is not assignable to expected type %s"
,
actual
.
getName
(),
expected
.
getName
()));
super
(
String
.
format
(
"Actual type %s is not assignable to expected type %s"
,
actual
.
getName
(),
expected
.
getName
()));
}
}
...
@@ -155,4 +154,5 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
...
@@ -155,4 +154,5 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver {
super
(
String
.
format
(
"Could not find/load class %s during attempt to convert to %s"
,
actual
,
expected
.
getName
()),
ex
);
super
(
String
.
format
(
"Could not find/load class %s during attempt to convert to %s"
,
actual
,
expected
.
getName
()),
ex
);
}
}
}
}
}
}
spring-core/src/main/java/org/springframework/core/io/ResourceEditor.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -19,12 +19,11 @@ package org.springframework.core.io;
...
@@ -19,12 +19,11 @@ package org.springframework.core.io;
import
java.beans.PropertyEditorSupport
;
import
java.beans.PropertyEditorSupport
;
import
java.io.IOException
;
import
java.io.IOException
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.PropertyResolver
;
import
org.springframework.core.env.PropertyResolver
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.util.Assert
;
import
org.springframework.util.Assert
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
* {@link java.beans.PropertyEditor Editor} for {@link Resource}
* {@link java.beans.PropertyEditor Editor} for {@link Resource}
* descriptors, to automatically convert {@code String} locations
* descriptors, to automatically convert {@code String} locations
...
@@ -51,7 +50,7 @@ public class ResourceEditor extends PropertyEditorSupport {
...
@@ -51,7 +50,7 @@ public class ResourceEditor extends PropertyEditorSupport {
private
final
ResourceLoader
resourceLoader
;
private
final
ResourceLoader
resourceLoader
;
private
final
PropertyResolver
propertyResolver
;
private
PropertyResolver
propertyResolver
;
private
final
boolean
ignoreUnresolvablePlaceholders
;
private
final
boolean
ignoreUnresolvablePlaceholders
;
...
@@ -61,7 +60,7 @@ public class ResourceEditor extends PropertyEditorSupport {
...
@@ -61,7 +60,7 @@ public class ResourceEditor extends PropertyEditorSupport {
* using a {@link DefaultResourceLoader} and {@link StandardEnvironment}.
* using a {@link DefaultResourceLoader} and {@link StandardEnvironment}.
*/
*/
public
ResourceEditor
()
{
public
ResourceEditor
()
{
this
(
new
DefaultResourceLoader
(),
n
ew
StandardEnvironment
()
);
this
(
new
DefaultResourceLoader
(),
n
ull
);
}
}
/**
/**
...
@@ -73,17 +72,7 @@ public class ResourceEditor extends PropertyEditorSupport {
...
@@ -73,17 +72,7 @@ public class ResourceEditor extends PropertyEditorSupport {
*/
*/
@Deprecated
@Deprecated
public
ResourceEditor
(
ResourceLoader
resourceLoader
)
{
public
ResourceEditor
(
ResourceLoader
resourceLoader
)
{
this
(
resourceLoader
,
new
StandardEnvironment
(),
true
);
this
(
resourceLoader
,
null
,
true
);
}
/**
* Create a new instance of the {@link ResourceEditor} class
* using the given {@link ResourceLoader} and {@link PropertyResolver}.
* @param resourceLoader the {@code ResourceLoader} to use
* @param propertyResolver the {@code PropertyResolver} to use
*/
public
ResourceEditor
(
ResourceLoader
resourceLoader
,
PropertyResolver
propertyResolver
)
{
this
(
resourceLoader
,
propertyResolver
,
true
);
}
}
/**
/**
...
@@ -97,7 +86,17 @@ public class ResourceEditor extends PropertyEditorSupport {
...
@@ -97,7 +86,17 @@ public class ResourceEditor extends PropertyEditorSupport {
*/
*/
@Deprecated
@Deprecated
public
ResourceEditor
(
ResourceLoader
resourceLoader
,
boolean
ignoreUnresolvablePlaceholders
)
{
public
ResourceEditor
(
ResourceLoader
resourceLoader
,
boolean
ignoreUnresolvablePlaceholders
)
{
this
(
resourceLoader
,
new
StandardEnvironment
(),
ignoreUnresolvablePlaceholders
);
this
(
resourceLoader
,
null
,
ignoreUnresolvablePlaceholders
);
}
/**
* Create a new instance of the {@link ResourceEditor} class
* using the given {@link ResourceLoader} and {@link PropertyResolver}.
* @param resourceLoader the {@code ResourceLoader} to use
* @param propertyResolver the {@code PropertyResolver} to use
*/
public
ResourceEditor
(
ResourceLoader
resourceLoader
,
PropertyResolver
propertyResolver
)
{
this
(
resourceLoader
,
propertyResolver
,
true
);
}
}
/**
/**
...
@@ -110,7 +109,6 @@ public class ResourceEditor extends PropertyEditorSupport {
...
@@ -110,7 +109,6 @@ public class ResourceEditor extends PropertyEditorSupport {
*/
*/
public
ResourceEditor
(
ResourceLoader
resourceLoader
,
PropertyResolver
propertyResolver
,
boolean
ignoreUnresolvablePlaceholders
)
{
public
ResourceEditor
(
ResourceLoader
resourceLoader
,
PropertyResolver
propertyResolver
,
boolean
ignoreUnresolvablePlaceholders
)
{
Assert
.
notNull
(
resourceLoader
,
"ResourceLoader must not be null"
);
Assert
.
notNull
(
resourceLoader
,
"ResourceLoader must not be null"
);
Assert
.
notNull
(
propertyResolver
,
"PropertyResolver must not be null"
);
this
.
resourceLoader
=
resourceLoader
;
this
.
resourceLoader
=
resourceLoader
;
this
.
propertyResolver
=
propertyResolver
;
this
.
propertyResolver
=
propertyResolver
;
this
.
ignoreUnresolvablePlaceholders
=
ignoreUnresolvablePlaceholders
;
this
.
ignoreUnresolvablePlaceholders
=
ignoreUnresolvablePlaceholders
;
...
@@ -137,9 +135,11 @@ public class ResourceEditor extends PropertyEditorSupport {
...
@@ -137,9 +135,11 @@ public class ResourceEditor extends PropertyEditorSupport {
* @see PropertyResolver#resolveRequiredPlaceholders
* @see PropertyResolver#resolveRequiredPlaceholders
*/
*/
protected
String
resolvePath
(
String
path
)
{
protected
String
resolvePath
(
String
path
)
{
return
this
.
ignoreUnresolvablePlaceholders
?
if
(
this
.
propertyResolver
==
null
)
{
this
.
propertyResolver
.
resolvePlaceholders
(
path
)
:
this
.
propertyResolver
=
new
StandardEnvironment
();
this
.
propertyResolver
.
resolveRequiredPlaceholders
(
path
);
}
return
(
this
.
ignoreUnresolvablePlaceholders
?
this
.
propertyResolver
.
resolvePlaceholders
(
path
)
:
this
.
propertyResolver
.
resolveRequiredPlaceholders
(
path
));
}
}
...
...
spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java
浏览文件 @
7e015785
/*
/*
* 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");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -25,10 +25,12 @@ import java.util.List;
...
@@ -25,10 +25,12 @@ import java.util.List;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.env.PropertyResolver
;
import
org.springframework.core.env.PropertyResolver
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.util.Assert
;
/**
/**
* Editor for {@link org.springframework.core.io.Resource} arrays, to
* Editor for {@link org.springframework.core.io.Resource} arrays, to
...
@@ -55,10 +57,10 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
...
@@ -55,10 +57,10 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
private
static
final
Log
logger
=
LogFactory
.
getLog
(
ResourceArrayPropertyEditor
.
class
);
private
static
final
Log
logger
=
LogFactory
.
getLog
(
ResourceArrayPropertyEditor
.
class
);
private
final
PropertyResolver
propertyResolver
;
private
final
ResourcePatternResolver
resourcePatternResolver
;
private
final
ResourcePatternResolver
resourcePatternResolver
;
private
PropertyResolver
propertyResolver
;
private
final
boolean
ignoreUnresolvablePlaceholders
;
private
final
boolean
ignoreUnresolvablePlaceholders
;
...
@@ -69,7 +71,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
...
@@ -69,7 +71,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
* @see Environment
* @see Environment
*/
*/
public
ResourceArrayPropertyEditor
()
{
public
ResourceArrayPropertyEditor
()
{
this
(
new
PathMatchingResourcePatternResolver
(),
n
ew
StandardEnvironment
()
,
true
);
this
(
new
PathMatchingResourcePatternResolver
(),
n
ull
,
true
);
}
}
/**
/**
...
@@ -80,17 +82,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
...
@@ -80,17 +82,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
*/
*/
@Deprecated
@Deprecated
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
)
{
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
)
{
this
(
resourcePatternResolver
,
new
StandardEnvironment
(),
true
);
this
(
resourcePatternResolver
,
null
,
true
);
}
/**
* Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
* and {@link PropertyResolver} (typically an {@link Environment}).
* @param resourcePatternResolver the ResourcePatternResolver to use
* @param propertyResolver the PropertyResolver to use
*/
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
,
PropertyResolver
propertyResolver
)
{
this
(
resourcePatternResolver
,
propertyResolver
,
true
);
}
}
/**
/**
...
@@ -103,7 +95,17 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
...
@@ -103,7 +95,17 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
*/
*/
@Deprecated
@Deprecated
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
,
boolean
ignoreUnresolvablePlaceholders
)
{
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
,
boolean
ignoreUnresolvablePlaceholders
)
{
this
(
resourcePatternResolver
,
new
StandardEnvironment
(),
ignoreUnresolvablePlaceholders
);
this
(
resourcePatternResolver
,
null
,
ignoreUnresolvablePlaceholders
);
}
/**
* Create a new ResourceArrayPropertyEditor with the given {@link ResourcePatternResolver}
* and {@link PropertyResolver} (typically an {@link Environment}).
* @param resourcePatternResolver the ResourcePatternResolver to use
* @param propertyResolver the PropertyResolver to use
*/
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
,
PropertyResolver
propertyResolver
)
{
this
(
resourcePatternResolver
,
propertyResolver
,
true
);
}
}
/**
/**
...
@@ -116,6 +118,8 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
...
@@ -116,6 +118,8 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
*/
*/
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
,
public
ResourceArrayPropertyEditor
(
ResourcePatternResolver
resourcePatternResolver
,
PropertyResolver
propertyResolver
,
boolean
ignoreUnresolvablePlaceholders
)
{
PropertyResolver
propertyResolver
,
boolean
ignoreUnresolvablePlaceholders
)
{
Assert
.
notNull
(
resourcePatternResolver
,
"ResourcePatternResolver must not be null"
);
this
.
resourcePatternResolver
=
resourcePatternResolver
;
this
.
resourcePatternResolver
=
resourcePatternResolver
;
this
.
propertyResolver
=
propertyResolver
;
this
.
propertyResolver
=
propertyResolver
;
this
.
ignoreUnresolvablePlaceholders
=
ignoreUnresolvablePlaceholders
;
this
.
ignoreUnresolvablePlaceholders
=
ignoreUnresolvablePlaceholders
;
...
@@ -197,9 +201,11 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
...
@@ -197,9 +201,11 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport {
* @see PropertyResolver#resolveRequiredPlaceholders(String)
* @see PropertyResolver#resolveRequiredPlaceholders(String)
*/
*/
protected
String
resolvePath
(
String
path
)
{
protected
String
resolvePath
(
String
path
)
{
return
this
.
ignoreUnresolvablePlaceholders
?
if
(
this
.
propertyResolver
==
null
)
{
this
.
propertyResolver
.
resolvePlaceholders
(
path
)
:
this
.
propertyResolver
=
new
StandardEnvironment
();
this
.
propertyResolver
.
resolveRequiredPlaceholders
(
path
);
}
return
(
this
.
ignoreUnresolvablePlaceholders
?
this
.
propertyResolver
.
resolvePlaceholders
(
path
)
:
this
.
propertyResolver
.
resolveRequiredPlaceholders
(
path
));
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录