Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
a5f9b292
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,发现更多精彩内容 >>
提交
a5f9b292
编写于
1月 15, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
91881ff0
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
52 addition
and
79 deletion
+52
-79
spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java
...springframework/core/env/ReadOnlySystemAttributesMap.java
+1
-1
spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java
...framework/test/context/support/AbstractContextLoader.java
+30
-45
spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java
...ext/support/AbstractRefreshableWebApplicationContext.java
+2
-4
spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java
...ork/web/context/support/GenericWebApplicationContext.java
+2
-4
spring-web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java
...ework/web/context/support/StandardServletEnvironment.java
+3
-5
spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java
...work/web/context/support/StaticWebApplicationContext.java
+2
-3
spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java
...ework/web/context/support/WebApplicationContextUtils.java
+9
-12
spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StaticPortletApplicationContext.java
.../web/portlet/context/StaticPortletApplicationContext.java
+3
-5
未找到文件。
spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java
浏览文件 @
a5f9b292
...
...
@@ -51,7 +51,7 @@ abstract class ReadOnlySystemAttributesMap implements Map<String, String> {
@Override
public
String
get
(
Object
key
)
{
Assert
.
isInstanceOf
(
String
.
class
,
key
,
String
.
format
(
"e
xpected key [%s] to be of type String, got %s"
,
key
,
key
.
getClass
().
getName
()));
String
.
format
(
"E
xpected key [%s] to be of type String, got %s"
,
key
,
key
.
getClass
().
getName
()));
return
this
.
getSystemAttribute
((
String
)
key
);
}
...
...
spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java
浏览文件 @
a5f9b292
...
...
@@ -61,11 +61,12 @@ import org.springframework.util.StringUtils;
*/
public
abstract
class
AbstractContextLoader
implements
SmartContextLoader
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
AbstractContextLoader
.
class
);
private
static
final
String
[]
EMPTY_STRING_ARRAY
=
new
String
[
0
];
private
static
final
String
SLASH
=
"/"
;
private
static
final
Log
logger
=
LogFactory
.
getLog
(
AbstractContextLoader
.
class
);
// --- SmartContextLoader -----------------------------------------------
...
...
@@ -79,24 +80,20 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
* processed locations are then
* {@link ContextConfigurationAttributes#setLocations(String[]) set} in
* the supplied configuration attributes.
*
* <p>Can be overridden in subclasses — for example, to process
* annotated classes instead of resource locations.
*
* @since 3.1
* @see #processLocations(Class, String...)
*/
@Override
public
void
processContextConfiguration
(
ContextConfigurationAttributes
configAttributes
)
{
String
[]
processedLocations
=
processLocations
(
configAttributes
.
getDeclaringClass
(),
configAttributes
.
getLocations
());
String
[]
processedLocations
=
processLocations
(
configAttributes
.
getDeclaringClass
(),
configAttributes
.
getLocations
());
configAttributes
.
setLocations
(
processedLocations
);
}
/**
* Prepare the {@link ConfigurableApplicationContext} created by this
* {@code SmartContextLoader} <i>before</i> bean definitions are read.
*
* <p>The default implementation:
* <ul>
* <li>Sets the <em>active bean definition profiles</em> from the supplied
...
...
@@ -107,17 +104,15 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
* {@linkplain ApplicationContextInitializer#initialize invokes each} with the
* given application context.</li>
* </ul>
*
* <p>Any {@code ApplicationContextInitializers} implementing
* {@link org.springframework.core.Ordered Ordered} or marked with {@link
* org.springframework.core.annotation.Order @Order} will be sorted appropriately.
*
* @param context the newly created application context
* @param mergedConfig the merged context configuration
* @since 3.2
* @see ApplicationContextInitializer#initialize(ConfigurableApplicationContext)
* @see #loadContext(MergedContextConfiguration)
* @see ConfigurableApplicationContext#setId
* @since 3.2
*/
@SuppressWarnings
(
"unchecked"
)
protected
void
prepareContext
(
ConfigurableApplicationContext
context
,
MergedContextConfiguration
mergedConfig
)
{
...
...
@@ -130,17 +125,18 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
return
;
}
final
List
<
ApplicationContextInitializer
<
ConfigurableApplicationContext
>>
initializerInstances
=
new
ArrayList
<
ApplicationContextInitializer
<
ConfigurableApplicationContext
>>();
final
Class
<?>
contextClass
=
context
.
getClass
();
List
<
ApplicationContextInitializer
<
ConfigurableApplicationContext
>>
initializerInstances
=
new
ArrayList
<
ApplicationContextInitializer
<
ConfigurableApplicationContext
>>();
Class
<?>
contextClass
=
context
.
getClass
();
for
(
Class
<?
extends
ApplicationContextInitializer
<?
extends
ConfigurableApplicationContext
>>
initializerClass
:
initializerClasses
)
{
Class
<?>
initializerContextClass
=
GenericTypeResolver
.
resolveTypeArgument
(
initializerClass
,
ApplicationContextInitializer
.
class
);
ApplicationContextInitializer
.
class
);
Assert
.
isAssignable
(
initializerContextClass
,
contextClass
,
String
.
format
(
"Could not add context initializer [%s] since its generic parameter [%s] "
+
"is not assignable from the type of application context used by this "
+
"context loader [%s]: "
,
initializerClass
.
getName
(),
initializerContextClass
.
getName
(),
contextClass
.
getName
()));
"Could not add context initializer [%s] since its generic parameter [%s] "
+
"is not assignable from the type of application context used by this "
+
"context loader [%s]: "
,
initializerClass
.
getName
(),
initializerContextClass
.
getName
(),
contextClass
.
getName
()));
initializerInstances
.
add
((
ApplicationContextInitializer
<
ConfigurableApplicationContext
>)
BeanUtils
.
instantiateClass
(
initializerClass
));
}
...
...
@@ -161,7 +157,6 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
* {@link #getResourceSuffix() resource suffix}; otherwise, the supplied
* {@code locations} will be {@link #modifyLocations modified} if
* necessary and returned.
*
* @param clazz the class with which the locations are associated: to be
* used when generating default locations
* @param locations the unmodified locations to use for loading the
...
...
@@ -176,29 +171,25 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
*/
@Override
public
final
String
[]
processLocations
(
Class
<?>
clazz
,
String
...
locations
)
{
return
(
ObjectUtils
.
isEmpty
(
locations
)
&&
isGenerateDefaultLocations
())
?
generateDefaultLocations
(
clazz
)
:
modifyLocations
(
clazz
,
locations
);
return
(
ObjectUtils
.
isEmpty
(
locations
)
&&
isGenerateDefaultLocations
())
?
generateDefaultLocations
(
clazz
)
:
modifyLocations
(
clazz
,
locations
);
}
/**
* Generate the default classpath resource locations array based on the
* supplied class.
*
* <p>For example, if the supplied class is {@code com.example.MyTest},
* the generated locations will contain a single string with a value of
* "classpath:/com/example/MyTest{@code <suffix>}",
* where {@code <suffix>} is the value of the
* {@link #getResourceSuffix() resource suffix} string.
*
* <p>As of Spring 3.1, the implementation of this method adheres to the
* contract defined in the {@link SmartContextLoader} SPI. Specifically,
* this method will <em>preemptively</em> verify that the generated default
* location actually exists. If it does not exist, this method will log a
* warning and return an empty array.
*
* <p>Subclasses can override this method to implement a different
* <em>default location generation</em> strategy.
*
* @param clazz the class for which the default locations are to be generated
* @return an array of default application context resource locations
* @since 2.5
...
...
@@ -214,23 +205,22 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
if
(
classPathResource
.
exists
())
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
String
.
format
(
"Detected default resource location \"%s\" for test class [%s]
.
"
,
prefixedResourcePath
,
clazz
.
getName
()));
logger
.
info
(
String
.
format
(
"Detected default resource location \"%s\" for test class [%s]"
,
prefixedResourcePath
,
clazz
.
getName
()));
}
return
new
String
[]
{
prefixedResourcePath
};
return
new
String
[]
{
prefixedResourcePath
};
}
// else
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
String
.
format
(
"Could not detect default resource locations for test class [%s]: "
+
"%s does not exist."
,
clazz
.
getName
(),
classPathResource
));
else
{
if
(
logger
.
isInfoEnabled
())
{
logger
.
info
(
String
.
format
(
"Could not detect default resource locations for test class [%s]: "
+
"%s does not exist"
,
clazz
.
getName
(),
classPathResource
));
}
return
EMPTY_STRING_ARRAY
;
}
return
EMPTY_STRING_ARRAY
;
}
/**
* Generate a modified version of the supplied locations array and return it.
*
* <p>A plain path — for example, "context.xml" — will
* be treated as a classpath resource that is relative to the package in which
* the specified class is defined. A path starting with a slash is treated
...
...
@@ -240,10 +230,8 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
* {@link ResourceUtils#CLASSPATH_URL_PREFIX classpath:},
* {@link ResourceUtils#FILE_URL_PREFIX file:}, {@code http:},
* etc.) will be added to the results unchanged.
*
* <p>Subclasses can override this method to implement a different
* <em>location modification</em> strategy.
*
* @param clazz the class with which the locations are associated
* @param locations the resource locations to be modified
* @return an array of modified application context resource locations
...
...
@@ -255,10 +243,12 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
String
path
=
locations
[
i
];
if
(
path
.
startsWith
(
SLASH
))
{
modifiedLocations
[
i
]
=
ResourceUtils
.
CLASSPATH_URL_PREFIX
+
path
;
}
else
if
(!
ResourcePatternUtils
.
isUrl
(
path
))
{
modifiedLocations
[
i
]
=
ResourceUtils
.
CLASSPATH_URL_PREFIX
+
SLASH
+
StringUtils
.
cleanPath
(
ClassUtils
.
classPackageAsResourcePath
(
clazz
)
+
SLASH
+
path
);
}
else
{
}
else
if
(!
ResourcePatternUtils
.
isUrl
(
path
))
{
modifiedLocations
[
i
]
=
ResourceUtils
.
CLASSPATH_URL_PREFIX
+
SLASH
+
StringUtils
.
cleanPath
(
ClassUtils
.
classPackageAsResourcePath
(
clazz
)
+
SLASH
+
path
);
}
else
{
modifiedLocations
[
i
]
=
StringUtils
.
cleanPath
(
path
);
}
}
...
...
@@ -269,7 +259,6 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
* Determine whether or not <em>default</em> resource locations should be
* generated if the {@code locations} provided to
* {@link #processLocations(Class, String...)} are {@code null} or empty.
*
* <p>As of Spring 3.1, the semantics of this method have been overloaded
* to include detection of either default resource locations or default
* configuration classes. Consequently, this method can also be used to
...
...
@@ -278,9 +267,7 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
* {@link ContextConfigurationAttributes configuration attributes} supplied
* to {@link #processContextConfiguration(ContextConfigurationAttributes)}
* are {@code null} or empty.
*
* <p>Can be overridden by subclasses to change the default behavior.
*
* @return always {@code true} by default
* @since 2.5
*/
...
...
@@ -291,9 +278,7 @@ public abstract class AbstractContextLoader implements SmartContextLoader {
/**
* Get the suffix to append to {@link ApplicationContext} resource locations
* when generating default locations.
*
* <p>Must be implemented by subclasses.
*
* @return the resource suffix; should not be {@code null} or empty
* @since 2.5
* @see #generateDefaultLocations(Class)
...
...
spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java
浏览文件 @
a5f9b292
...
...
@@ -197,11 +197,9 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
*/
@Override
protected
void
initPropertySources
()
{
super
.
initPropertySources
();
ConfigurableEnvironment
env
=
this
.
getEnvironment
();
ConfigurableEnvironment
env
=
getEnvironment
();
if
(
env
instanceof
ConfigurableWebEnvironment
)
{
((
ConfigurableWebEnvironment
)
env
).
initPropertySources
(
this
.
servletContext
,
this
.
servletConfig
);
((
ConfigurableWebEnvironment
)
env
).
initPropertySources
(
this
.
servletContext
,
this
.
servletConfig
);
}
}
...
...
spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java
浏览文件 @
a5f9b292
...
...
@@ -183,11 +183,9 @@ public class GenericWebApplicationContext extends GenericApplicationContext
*/
@Override
protected
void
initPropertySources
()
{
super
.
initPropertySources
();
ConfigurableEnvironment
env
=
this
.
getEnvironment
();
ConfigurableEnvironment
env
=
getEnvironment
();
if
(
env
instanceof
ConfigurableWebEnvironment
)
{
((
ConfigurableWebEnvironment
)
env
).
initPropertySources
(
this
.
servletContext
,
null
);
((
ConfigurableWebEnvironment
)
env
).
initPropertySources
(
this
.
servletContext
,
null
);
}
}
...
...
spring-web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java
浏览文件 @
a5f9b292
/*
* 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.
...
...
@@ -41,8 +41,7 @@ import org.springframework.web.context.ConfigurableWebEnvironment;
* @since 3.1
* @see StandardEnvironment
*/
public
class
StandardServletEnvironment
extends
StandardEnvironment
implements
ConfigurableWebEnvironment
{
public
class
StandardServletEnvironment
extends
StandardEnvironment
implements
ConfigurableWebEnvironment
{
/** Servlet context init parameters property source name: {@value} */
public
static
final
String
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
=
"servletContextInitParams"
;
...
...
@@ -92,8 +91,7 @@ public class StandardServletEnvironment extends StandardEnvironment
@Override
public
void
initPropertySources
(
ServletContext
servletContext
,
ServletConfig
servletConfig
)
{
WebApplicationContextUtils
.
initServletPropertySources
(
this
.
getPropertySources
(),
servletContext
,
servletConfig
);
WebApplicationContextUtils
.
initServletPropertySources
(
getPropertySources
(),
servletContext
,
servletConfig
);
}
}
spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java
浏览文件 @
a5f9b292
...
...
@@ -186,9 +186,8 @@ public class StaticWebApplicationContext extends StaticApplicationContext
@Override
protected
void
initPropertySources
()
{
super
.
initPropertySources
();
WebApplicationContextUtils
.
initServletPropertySources
(
this
.
getEnvironment
().
getPropertySources
(),
this
.
servletContext
,
this
.
servletConfig
);
WebApplicationContextUtils
.
initServletPropertySources
(
getEnvironment
().
getPropertySources
(),
this
.
servletContext
,
this
.
servletConfig
);
}
@Override
...
...
spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java
浏览文件 @
a5f9b292
...
...
@@ -16,15 +16,11 @@
package
org.springframework.web.context.support
;
import
static
org
.
springframework
.
web
.
context
.
support
.
StandardServletEnvironment
.
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
;
import
static
org
.
springframework
.
web
.
context
.
support
.
StandardServletEnvironment
.
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
;
import
java.io.Serializable
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.faces.context.ExternalContext
;
import
javax.faces.context.FacesContext
;
import
javax.servlet.ServletConfig
;
...
...
@@ -259,16 +255,17 @@ public abstract class WebApplicationContextUtils {
*/
public
static
void
initServletPropertySources
(
MutablePropertySources
propertySources
,
ServletContext
servletContext
,
ServletConfig
servletConfig
)
{
Assert
.
notNull
(
propertySources
,
"propertySources must not be null"
);
if
(
servletContext
!=
null
&&
propertySources
.
contains
(
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
)
&&
propertySources
.
get
(
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
)
instanceof
StubPropertySource
)
{
propertySources
.
replace
(
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
,
new
ServletContextPropertySource
(
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
,
servletContext
));
if
(
servletContext
!=
null
&&
propertySources
.
contains
(
StandardServletEnvironment
.
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
)
&&
propertySources
.
get
(
StandardServletEnvironment
.
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
)
instanceof
StubPropertySource
)
{
propertySources
.
replace
(
StandardServletEnvironment
.
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
,
new
ServletContextPropertySource
(
StandardServletEnvironment
.
SERVLET_CONTEXT_PROPERTY_SOURCE_NAME
,
servletContext
));
}
if
(
servletConfig
!=
null
&&
propertySources
.
contains
(
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
)
&&
propertySources
.
get
(
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
)
instanceof
StubPropertySource
)
{
propertySources
.
replace
(
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
,
new
ServletConfigPropertySource
(
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
,
servletConfig
));
if
(
servletConfig
!=
null
&&
propertySources
.
contains
(
StandardServletEnvironment
.
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
)
&&
propertySources
.
get
(
StandardServletEnvironment
.
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
)
instanceof
StubPropertySource
)
{
propertySources
.
replace
(
StandardServletEnvironment
.
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
,
new
ServletConfigPropertySource
(
StandardServletEnvironment
.
SERVLET_CONFIG_PROPERTY_SOURCE_NAME
,
servletConfig
));
}
}
...
...
spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StaticPortletApplicationContext.java
浏览文件 @
a5f9b292
/*
* 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.
...
...
@@ -78,10 +78,8 @@ public class StaticPortletApplicationContext extends StaticApplicationContext
*/
@Override
protected
void
initPropertySources
()
{
super
.
initPropertySources
();
PortletApplicationContextUtils
.
initPortletPropertySources
(
this
.
getEnvironment
().
getPropertySources
(),
this
.
servletContext
,
this
.
portletContext
,
this
.
portletConfig
);
PortletApplicationContextUtils
.
initPortletPropertySources
(
getEnvironment
().
getPropertySources
(),
this
.
servletContext
,
this
.
portletContext
,
this
.
portletConfig
);
}
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录