M1 cut of environment, profiles and property work (SPR-7508)
Decomposed Environment interface into PropertySources, PropertyResolver
objects
Environment interface and implementations are still present, but
simpler.
PropertySources container aggregates PropertySource objects;
PropertyResolver provides search, conversion, placeholder
replacement. Single implementation for now is
PropertySourcesPlaceholderResolver
Renamed EnvironmentAwarePropertyPlaceholderConfigurer to
PropertySourcesPlaceholderConfigurer
<context:property-placeholder/> now registers PSPC by default, else
PPC if systemPropertiesMode* settings are involved
Refined configuration and behavior of default profiles
See Environment interface Javadoc for details
Added Portlet implementations of relevant interfaces:
* DefaultPortletEnvironment
* PortletConfigPropertySource, PortletContextPropertySource
* Integrated each appropriately throughout Portlet app contexts
Added protected 'createEnvironment()' method to AbstractApplicationContext
Subclasses can override at will to supply a custom Environment
implementation. In practice throughout the framework, this is how
Web- and Portlet-related ApplicationContexts override use of the
DefaultEnvironment and swap in DefaultWebEnvironment or
DefaultPortletEnvironment as appropriate.
Introduced "stub-and-replace" behavior for Servlet- and Portlet-based
PropertySource implementations
Allows for early registration and ordering of the stub, then
replacement with actual backing object at refresh() time.
Added AbstractApplicationContext.initPropertySources() method to
support stub-and-replace behavior. Called from within existing
prepareRefresh() method so as to avoid impact with
ApplicationContext implementations that copy and modify AAC's
refresh() method (e.g.: Spring DM).
Added methods to WebApplicationContextUtils and
PortletApplicationContextUtils to support stub-and-replace behavior
Added comprehensive Javadoc for all new or modified types and members
Added XSD documentation for all new or modified elements and attributes
Including nested <beans>, <beans profile="..."/>, and changes for
certain attributes type from xsd:IDREF to xsd:string
Improved fix for detecting non-file based Resources in
PropertiesLoaderSupport (SPR-7547, SPR-7552)
Technically unrelated to environment work, but grouped in with
this changeset for convenience.
Deprecated (removed) context:property-placeholder
'system-properties-mode' attribute from spring-context-3.1.xsd
Functionality is preserved for those using schemas up to and including
spring-context-3.0. For 3.1, system-properties-mode is no longer
supported as it conflicts with the idea of managing a set of property
sources within the context's Environment object. See Javadoc in
PropertyPlaceholderConfigurer, AbstractPropertyPlaceholderConfigurer
and PropertySourcesPlaceholderConfigurer for details.
Introduced CollectionUtils.toArray(Enumeration<E>, A[])
Work items remaining for 3.1 M2:
Consider repackaging PropertySource* types; eliminate internal use
of SystemPropertyUtils and deprecate
Further work on composition of Environment interface; consider
repurposing existing PlaceholderResolver interface to obviate need
for resolve[Required]Placeholder() methods currently in Environment.
Ensure configurability of placeholder prefix, suffix, and value
separator when working against an AbstractPropertyResolver
Add JNDI-based Environment / PropertySource implementatinos
Consider support for @Profile at the @Bean level
Provide consistent logging for the entire property resolution
lifecycle; consider issuing all such messages against a dedicated
logger with a single category.
Add reference documentation to cover the featureset.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2009 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,7 +21,7 @@ import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.support.AbstractRefreshableConfigApplicationContext;
|
||||
import org.springframework.core.env.DefaultWebEnvironment;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.ui.context.Theme;
|
||||
@@ -93,14 +93,11 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||
|
||||
public AbstractRefreshableWebApplicationContext() {
|
||||
setDisplayName("Root WebApplicationContext");
|
||||
setEnvironment(new DefaultWebEnvironment());
|
||||
}
|
||||
|
||||
|
||||
public void setServletContext(ServletContext servletContext) {
|
||||
this.servletContext = servletContext;
|
||||
// TODO: SPR-7508 extract createEnvironment() method; do also in GWAC
|
||||
this.getEnvironment().getPropertySources().addFirst(new ServletContextPropertySource(this.servletContext));
|
||||
}
|
||||
|
||||
public ServletContext getServletContext() {
|
||||
@@ -112,8 +109,6 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||
if (servletConfig != null && this.servletContext == null) {
|
||||
this.setServletContext(servletConfig.getServletContext());
|
||||
}
|
||||
// TODO: SPR-7508 extract createEnvironment() method; do also in GWAC
|
||||
this.getEnvironment().getPropertySources().addFirst(new ServletConfigPropertySource(servletConfig));
|
||||
}
|
||||
|
||||
public ServletConfig getServletConfig() {
|
||||
@@ -136,6 +131,14 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||
return super.getConfigLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a new {@link DefaultWebEnvironment}.
|
||||
*/
|
||||
@Override
|
||||
protected ConfigurableEnvironment createEnvironment() {
|
||||
return new DefaultWebEnvironment();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register request/session scopes, a {@link ServletContextAwareProcessor}, etc.
|
||||
@@ -176,6 +179,18 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR
|
||||
this.themeSource = UiApplicationContextUtils.initThemeSource(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Replace {@code Servlet}-related property sources.
|
||||
*/
|
||||
@Override
|
||||
protected void initPropertySources() {
|
||||
super.initPropertySources();
|
||||
WebApplicationContextUtils.initServletPropertySources(
|
||||
this.getEnvironment().getPropertySources(), this.servletContext,
|
||||
this.servletConfig);
|
||||
}
|
||||
|
||||
public Theme getTheme(String themeName) {
|
||||
return this.themeSource.getTheme(themeName);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver;
|
||||
* which accepts annotated classes as input - in particular
|
||||
* {@link org.springframework.context.annotation.Configuration @Configuration}-annotated
|
||||
* classes, but also plain {@link org.springframework.stereotype.Component @Components}
|
||||
* and JSR-330 compliant classes using {@literal javax.inject} annotations. Allows for
|
||||
* and JSR-330 compliant classes using {@code javax.inject} annotations. Allows for
|
||||
* registering classes one by one (specifying class names as config location) as well
|
||||
* as for classpath scanning (specifying base packages as config location).
|
||||
*
|
||||
@@ -46,7 +46,7 @@ import org.springframework.context.annotation.ScopeMetadataResolver;
|
||||
* FrameworkServlet. The param-value may contain both fully-qualified
|
||||
* class names and base packages to scan for components.
|
||||
*
|
||||
* <p>Note: In case of multiple {@literal @Configuration} classes, later {@literal @Bean}
|
||||
* <p>Note: In case of multiple {@code @Configuration} classes, later {@code @Bean}
|
||||
* definitions will override ones defined in earlier loaded files. This can be leveraged
|
||||
* to deliberately override certain bean definitions via an extra Configuration class.
|
||||
*
|
||||
@@ -60,10 +60,10 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
|
||||
/**
|
||||
* Register a {@link BeanDefinition} for each class specified by {@link #getConfigLocations()},
|
||||
* or scan each specified package for annotated classes. Enables the default set of
|
||||
* annotation configuration post processors, such that {@literal @Autowired},
|
||||
* {@literal @Required}, and associated annotations can be used.
|
||||
* annotation configuration post processors, such that {@code @Autowired},
|
||||
* {@code @Required}, and associated annotations can be used.
|
||||
* <p>Configuration class bean definitions are registered with generated bean definition
|
||||
* names unless the {@literal value} attribute is provided to the stereotype annotation.
|
||||
* names unless the {@code value} attribute is provided to the stereotype annotation.
|
||||
* @see #getConfigLocations()
|
||||
* @see AnnotatedBeanDefinitionReader
|
||||
* @see ClassPathBeanDefinitionScanner
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.core.env.DefaultEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.PropertySource.StubPropertySource;
|
||||
|
||||
/**
|
||||
* {@link Environment} implementation to be used by {@code Servlet}-based web
|
||||
* applications. All web-related (servlet-based) {@code ApplicationContext} classes
|
||||
* initialize an instance by default.
|
||||
*
|
||||
* <p>Contributes {@code ServletConfig}- and {@code ServletContext}-based {@link PropertySource}
|
||||
* instances. See the {@link #DefaultWebEnvironment()} constructor for details.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
* @see DefaultEnvironment
|
||||
* @see DefaultPortletEnvironment
|
||||
*/
|
||||
public class DefaultWebEnvironment extends DefaultEnvironment {
|
||||
|
||||
/** Servlet context init parameters property source name: {@value} */
|
||||
public static final String SERVLET_CONTEXT_PROPERTY_SOURCE_NAME = "servletContextInitParams";
|
||||
|
||||
/** Servlet config init parameters property source name: {@value} */
|
||||
public static final String SERVLET_CONFIG_PROPERTY_SOURCE_NAME = "servletConfigInitParams";
|
||||
|
||||
/**
|
||||
* Create a new {@code Environment} populated with the property sources contributed by
|
||||
* superclasses as well as:
|
||||
* <ul>
|
||||
* <li>{@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME}
|
||||
* <li>{@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}
|
||||
* </ul>
|
||||
* <p>Properties present in {@value #SERVLET_CONFIG_PROPERTY_SOURCE_NAME} will
|
||||
* take precedence over those in {@value #SERVLET_CONTEXT_PROPERTY_SOURCE_NAME}.
|
||||
* Properties in either will take precedence over system properties and environment
|
||||
* variables.
|
||||
* <p>The {@code Servlet}-related property sources are added as stubs for now, and will be
|
||||
* {@linkplain WebApplicationContextUtils#initServletPropertySources fully initialized}
|
||||
* once the actual {@link ServletConfig} and {@link ServletContext} objects are available.
|
||||
* @see DefaultEnvironment#DefaultEnvironment
|
||||
* @see ServletConfigPropertySource
|
||||
* @see ServletContextPropertySource
|
||||
* @see org.springframework.context.support.AbstractApplicationContext#initPropertySources
|
||||
* @see WebApplicationContextUtils#initServletPropertySources
|
||||
*/
|
||||
public DefaultWebEnvironment() {
|
||||
this.getPropertySources().addFirst(new StubPropertySource(SERVLET_CONTEXT_PROPERTY_SOURCE_NAME));
|
||||
this.getPropertySources().addFirst(new StubPropertySource(SERVLET_CONFIG_PROPERTY_SOURCE_NAME));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2009 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,7 +21,7 @@ import javax.servlet.ServletContext;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.env.DefaultWebEnvironment;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.ui.context.Theme;
|
||||
@@ -61,12 +61,6 @@ public class GenericWebApplicationContext extends GenericApplicationContext
|
||||
|
||||
private ThemeSource themeSource;
|
||||
|
||||
// override superclass definition of environment
|
||||
// TODO SPR-7508: polish
|
||||
{
|
||||
this.setEnvironment(new DefaultWebEnvironment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new GenericWebApplicationContext.
|
||||
* @see #setServletContext
|
||||
@@ -123,6 +117,14 @@ public class GenericWebApplicationContext extends GenericApplicationContext
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create and return a new {@link DefaultWebEnvironment}.
|
||||
*/
|
||||
@Override
|
||||
protected ConfigurableEnvironment createEnvironment() {
|
||||
return new DefaultWebEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register ServletContextAwareProcessor.
|
||||
* @see ServletContextAwareProcessor
|
||||
@@ -160,7 +162,17 @@ public class GenericWebApplicationContext extends GenericApplicationContext
|
||||
@Override
|
||||
protected void onRefresh() {
|
||||
this.themeSource = UiApplicationContextUtils.initThemeSource(this);
|
||||
this.getEnvironment().getPropertySources().addFirst(new ServletContextPropertySource(servletContext));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>Replace {@code Servlet}-related property sources.
|
||||
*/
|
||||
@Override
|
||||
protected void initPropertySources() {
|
||||
super.initPropertySources();
|
||||
WebApplicationContextUtils.initServletPropertySources(
|
||||
this.getEnvironment().getPropertySources(), this.servletContext);
|
||||
}
|
||||
|
||||
public Theme getTheme(String themeName) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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,36 +20,27 @@ import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
|
||||
import org.springframework.core.env.DefaultWebEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* TODO SPR-7508: document
|
||||
*
|
||||
* {@link PropertySource} that reads init parameters from a {@link ServletConfig} object.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
* @see ServletContextPropertySource
|
||||
*/
|
||||
public class ServletConfigPropertySource extends PropertySource<ServletConfig> {
|
||||
|
||||
public ServletConfigPropertySource(ServletConfig servletConfig) {
|
||||
this(DefaultWebEnvironment.SERVLET_CONFIG_PARAMS_PROPERTY_SOURCE_NAME, servletConfig);
|
||||
}
|
||||
|
||||
public ServletConfigPropertySource(String name, ServletConfig servletConfig) {
|
||||
super(name, servletConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsProperty(String name) {
|
||||
Enumeration<?> initParamNames = this.source.getInitParameterNames();
|
||||
while (initParamNames.hasMoreElements()) {
|
||||
if (initParamNames.nextElement().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@SuppressWarnings("unchecked")
|
||||
public String[] getPropertyNames() {
|
||||
return CollectionUtils.toArray(
|
||||
(Enumeration<String>)this.source.getInitParameterNames(), EMPTY_NAMES_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,14 +48,4 @@ public class ServletConfigPropertySource extends PropertySource<ServletConfig> {
|
||||
return this.source.getInitParameter(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size=0;
|
||||
Enumeration<?> initParamNames = this.source.getInitParameterNames();
|
||||
while (initParamNames.hasMoreElements()) {
|
||||
initParamNames.nextElement();
|
||||
size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,11 @@ import java.util.Properties;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.context.support.EnvironmentAwarePropertyPlaceholderConfigurer;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
|
||||
|
||||
/**
|
||||
* Subclass of PropertyPlaceholderConfigurer that resolves placeholders as
|
||||
* Subclass of {@link PropertyPlaceholderConfigurer} that resolves placeholders as
|
||||
* ServletContext init parameters (that is, <code>web.xml</code> context-param
|
||||
* entries).
|
||||
*
|
||||
@@ -59,8 +58,8 @@ import org.springframework.web.context.ServletContextAware;
|
||||
* @see #setSearchContextAttributes
|
||||
* @see javax.servlet.ServletContext#getInitParameter(String)
|
||||
* @see javax.servlet.ServletContext#getAttribute(String)
|
||||
* @deprecated in Spring 3.1 in favor of {@link EnvironmentAwarePropertyPlaceholderConfigurer}
|
||||
* in conjunction with {@link org.springframework.core.env.DefaultWebEnvironment}.
|
||||
* @deprecated in Spring 3.1 in favor of {@link org.springframework.context.support.PropertySourcesPlaceholderConfigurer}
|
||||
* in conjunction with {@link org.springframework.web.context.support.DefaultWebEnvironment}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ServletContextPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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,12 +20,11 @@ import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.core.env.DefaultWebEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* TODO SPR-7508: document
|
||||
* {@link PropertySource} that reads init parameters from a {@link ServletContext} object.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
@@ -33,38 +32,19 @@ import org.springframework.core.env.PropertySource;
|
||||
*/
|
||||
public class ServletContextPropertySource extends PropertySource<ServletContext> {
|
||||
|
||||
public ServletContextPropertySource(ServletContext servletContext) {
|
||||
this(DefaultWebEnvironment.SERVLET_CONTEXT_PARAMS_PROPERTY_SOURCE_NAME, servletContext);
|
||||
}
|
||||
|
||||
public ServletContextPropertySource(String name, ServletContext servletContext) {
|
||||
super(name, servletContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsProperty(String name) {
|
||||
Enumeration<?> initParamNames = this.source.getInitParameterNames();
|
||||
while (initParamNames.hasMoreElements()) {
|
||||
if (initParamNames.nextElement().equals(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@SuppressWarnings("unchecked")
|
||||
public String[] getPropertyNames() {
|
||||
return CollectionUtils.toArray(
|
||||
(Enumeration<String>)this.source.getInitParameterNames(), EMPTY_NAMES_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String name) {
|
||||
return this.source.getInitParameter(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size=0;
|
||||
Enumeration<?> initParamNames = this.source.getInitParameterNames();
|
||||
while (initParamNames.hasMoreElements()) {
|
||||
initParamNames.nextElement();
|
||||
size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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,14 +16,12 @@
|
||||
|
||||
package org.springframework.web.context.support;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.env.DefaultWebEnvironment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
||||
import org.springframework.ui.context.Theme;
|
||||
@@ -69,7 +67,6 @@ public class StaticWebApplicationContext extends StaticApplicationContext
|
||||
|
||||
public StaticWebApplicationContext() {
|
||||
setDisplayName("Root WebApplicationContext");
|
||||
setEnvironment(new DefaultWebEnvironment()); // TODO SPR-7508: see GenericWebApplicationContext, AbstractRefreshableWebApplicationContext
|
||||
}
|
||||
|
||||
|
||||
@@ -162,15 +159,27 @@ public class StaticWebApplicationContext extends StaticApplicationContext
|
||||
return new ServletContextResourcePatternResolver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a new {@link DefaultWebEnvironment}.
|
||||
*/
|
||||
@Override
|
||||
protected ConfigurableEnvironment createEnvironment() {
|
||||
return new DefaultWebEnvironment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the theme capability.
|
||||
*/
|
||||
@Override
|
||||
protected void onRefresh() {
|
||||
this.themeSource = UiApplicationContextUtils.initThemeSource(this);
|
||||
LinkedList<PropertySource<?>> propertySources = this.getEnvironment().getPropertySources();
|
||||
propertySources.addFirst(new ServletContextPropertySource(servletContext));
|
||||
propertySources.addFirst(new ServletConfigPropertySource(servletConfig));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initPropertySources() {
|
||||
super.initPropertySources();
|
||||
WebApplicationContextUtils.initServletPropertySources(
|
||||
this.getEnvironment().getPropertySources(), this.servletContext, this.servletConfig);
|
||||
}
|
||||
|
||||
public Theme getTheme(String themeName) {
|
||||
|
||||
@@ -21,6 +21,7 @@ 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;
|
||||
@@ -30,6 +31,7 @@ import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
@@ -192,14 +194,14 @@ public abstract class WebApplicationContextUtils {
|
||||
if (!bf.containsBean(WebApplicationContext.CONTEXT_PARAMETERS_BEAN_NAME)) {
|
||||
Map<String, String> parameterMap = new HashMap<String, String>();
|
||||
if (sc != null) {
|
||||
Enumeration paramNameEnum = sc.getInitParameterNames();
|
||||
Enumeration<?> paramNameEnum = sc.getInitParameterNames();
|
||||
while (paramNameEnum.hasMoreElements()) {
|
||||
String paramName = (String) paramNameEnum.nextElement();
|
||||
parameterMap.put(paramName, sc.getInitParameter(paramName));
|
||||
}
|
||||
}
|
||||
if (config != null) {
|
||||
Enumeration paramNameEnum = config.getInitParameterNames();
|
||||
Enumeration<?> paramNameEnum = config.getInitParameterNames();
|
||||
while (paramNameEnum.hasMoreElements()) {
|
||||
String paramName = (String) paramNameEnum.nextElement();
|
||||
parameterMap.put(paramName, config.getInitParameter(paramName));
|
||||
@@ -212,7 +214,7 @@ public abstract class WebApplicationContextUtils {
|
||||
if (!bf.containsBean(WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME)) {
|
||||
Map<String, Object> attributeMap = new HashMap<String, Object>();
|
||||
if (sc != null) {
|
||||
Enumeration attrNameEnum = sc.getAttributeNames();
|
||||
Enumeration<?> attrNameEnum = sc.getAttributeNames();
|
||||
while (attrNameEnum.hasMoreElements()) {
|
||||
String attrName = (String) attrNameEnum.nextElement();
|
||||
attributeMap.put(attrName, sc.getAttribute(attrName));
|
||||
@@ -223,6 +225,38 @@ public abstract class WebApplicationContextUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace {@code Servlet}-based stub property sources with actual instances
|
||||
* populated with the given context object.
|
||||
* @see org.springframework.core.env.PropertySource.StubPropertySource
|
||||
* @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources()
|
||||
* @see org.springframework.web.context.support.WebApplicationContextUtils#initServletPropertySources(MutablePropertySources, ServletContext)
|
||||
*/
|
||||
public static void initServletPropertySources(
|
||||
MutablePropertySources propertySources, ServletContext servletContext) {
|
||||
initServletPropertySources(propertySources, servletContext, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace {@code Servlet}-based stub property sources with actual instances
|
||||
* populated with the given context and config objects.
|
||||
* @see org.springframework.core.env.PropertySource.StubPropertySource
|
||||
* @see org.springframework.web.context.support.WebApplicationContextUtils#initServletPropertySources(MutablePropertySources, ServletContext)
|
||||
* @see org.springframework.core.env.ConfigurableEnvironment#getPropertySources()
|
||||
*/
|
||||
public static void initServletPropertySources(
|
||||
MutablePropertySources propertySources, ServletContext servletContext, ServletConfig servletConfig) {
|
||||
Assert.notNull(propertySources, "propertySources must not be null");
|
||||
if(servletContext != null && propertySources.contains(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)) {
|
||||
propertySources.replace(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME,
|
||||
new ServletContextPropertySource(DefaultWebEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME, servletContext));
|
||||
}
|
||||
if(servletConfig != null && propertySources.contains(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)) {
|
||||
propertySources.replace(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME,
|
||||
new ServletConfigPropertySource(DefaultWebEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME, servletConfig));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current RequestAttributes instance as ServletRequestAttributes.
|
||||
* @see RequestContextHolder#currentRequestAttributes()
|
||||
@@ -239,6 +273,7 @@ public abstract class WebApplicationContextUtils {
|
||||
/**
|
||||
* Factory that exposes the current request object on demand.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private static class RequestObjectFactory implements ObjectFactory<ServletRequest>, Serializable {
|
||||
|
||||
public ServletRequest getObject() {
|
||||
@@ -255,6 +290,7 @@ public abstract class WebApplicationContextUtils {
|
||||
/**
|
||||
* Factory that exposes the current session object on demand.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private static class SessionObjectFactory implements ObjectFactory<HttpSession>, Serializable {
|
||||
|
||||
public HttpSession getObject() {
|
||||
@@ -271,6 +307,7 @@ public abstract class WebApplicationContextUtils {
|
||||
/**
|
||||
* Factory that exposes the current WebRequest object on demand.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private static class WebRequestObjectFactory implements ObjectFactory<WebRequest>, Serializable {
|
||||
|
||||
public WebRequest getObject() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -38,7 +38,6 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.DefaultWebEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceEditor;
|
||||
@@ -46,6 +45,7 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.context.ServletContextAware;
|
||||
import org.springframework.web.context.support.DefaultWebEnvironment;
|
||||
import org.springframework.web.context.support.ServletContextResourceLoader;
|
||||
import org.springframework.web.util.NestedServletException;
|
||||
|
||||
@@ -88,16 +88,10 @@ public abstract class GenericFilterBean implements
|
||||
*/
|
||||
private final Set<String> requiredProperties = new HashSet<String>();
|
||||
|
||||
/* The FilterConfig of this filter */
|
||||
private FilterConfig filterConfig;
|
||||
|
||||
private String beanName;
|
||||
|
||||
/**
|
||||
* TODO SPR-7508: document
|
||||
* Defaults to {@link DefaultWebEnvironment}; can be overriden if deployed
|
||||
* as a spring bean by {@link #setEnvironment(Environment)}
|
||||
*/
|
||||
private Environment environment = new DefaultWebEnvironment();
|
||||
|
||||
private ServletContext servletContext;
|
||||
@@ -115,7 +109,9 @@ public abstract class GenericFilterBean implements
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO SPR-7508: document
|
||||
* {@inheritDoc}
|
||||
* <p>Any environment set here overrides the {@link DefaultWebEnvironment}
|
||||
* provided by default.
|
||||
*/
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
@@ -282,6 +278,7 @@ public abstract class GenericFilterBean implements
|
||||
/**
|
||||
* PropertyValues implementation created from FilterConfig init parameters.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private static class FilterConfigPropertyValues extends MutablePropertyValues {
|
||||
|
||||
/**
|
||||
@@ -292,12 +289,12 @@ public abstract class GenericFilterBean implements
|
||||
* @throws ServletException if any required properties are missing
|
||||
*/
|
||||
public FilterConfigPropertyValues(FilterConfig config, Set<String> requiredProperties)
|
||||
throws ServletException {
|
||||
throws ServletException {
|
||||
|
||||
Set<String> missingProps = (requiredProperties != null && !requiredProperties.isEmpty()) ?
|
||||
new HashSet<String>(requiredProperties) : null;
|
||||
|
||||
Enumeration en = config.getInitParameterNames();
|
||||
Enumeration<?> en = config.getInitParameterNames();
|
||||
while (en.hasMoreElements()) {
|
||||
String property = (String) en.nextElement();
|
||||
Object value = config.getInitParameter(property);
|
||||
|
||||
Reference in New Issue
Block a user