FrameworkPortlet properly initializes StandardPortletEnvironment's property sources

Issue: SPR-11816
This commit is contained in:
Juergen Hoeller 2014-06-05 15:09:02 +02:00
parent 5a8e470ede
commit 8fb0f5c7d1
2 changed files with 33 additions and 6 deletions

View File

@ -41,12 +41,14 @@ import org.springframework.context.event.SourceFilteringListener;
import org.springframework.context.i18n.LocaleContext;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.i18n.SimpleLocaleContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.portlet.context.ConfigurablePortletApplicationContext;
import org.springframework.web.portlet.context.PortletApplicationContextUtils;
import org.springframework.web.portlet.context.PortletRequestAttributes;
import org.springframework.web.portlet.context.PortletRequestHandledEvent;
import org.springframework.web.portlet.context.StandardPortletEnvironment;
import org.springframework.web.portlet.context.XmlPortletApplicationContext;
/**
@ -353,6 +355,14 @@ public abstract class FrameworkPortlet extends GenericPortletBean
pac.setConfigLocation(getContextConfigLocation());
pac.addApplicationListener(new SourceFilteringListener(pac, this));
// The wac environment's #initPropertySources will be called in any case when the context
// is refreshed; do it eagerly here to ensure portlet property sources are in place for
// use in any post-processing or initialization that occurs below prior to #refresh
ConfigurableEnvironment env = pac.getEnvironment();
if (env instanceof StandardPortletEnvironment) {
((StandardPortletEnvironment) env).initPropertySources(pac.getServletContext(), getPortletContext(), getPortletConfig());
}
postProcessPortletApplicationContext(pac);
pac.refresh();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@ -31,14 +31,15 @@ import org.springframework.web.context.support.StandardServletEnvironment;
/**
* {@link Environment} implementation to be used by {@code Servlet}-based web
* applications. All Portlet-related {@code ApplicationContext} classes initialize an instance
* by default.
* applications. All Portlet-related {@code ApplicationContext} classes
* initialize an instance by default.
*
* <p>Contributes {@code ServletContext}, {@code PortletContext}, {@code PortletConfig}
* and JNDI-based {@link PropertySource} instances. See the
* {@link #customizePropertySources} method for details.
* <p>Contributes {@code ServletContext}, {@code PortletContext},
* {@code PortletConfig} and JNDI-based {@link PropertySource} instances.
* See the {@link #customizePropertySources} method for details.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @see StandardEnvironment
* @see StandardServletEnvironment
@ -51,6 +52,7 @@ public class StandardPortletEnvironment extends StandardEnvironment {
/** Portlet config init parameters property source name: {@value} */
public static final String PORTLET_CONFIG_PROPERTY_SOURCE_NAME = "portletConfigInitParams";
/**
* Customize the set of property sources with those contributed by superclasses as
* well as those appropriate for standard portlet-based environments:
@ -88,4 +90,19 @@ public class StandardPortletEnvironment extends StandardEnvironment {
super.customizePropertySources(propertySources);
}
/**
* Replace any {@linkplain
* org.springframework.core.env.PropertySource.StubPropertySource stub property source}
* instances acting as placeholders with real portlet context/config property sources
* using the given parameters.
* @param servletContext the {@link ServletContext} (may be {@code null})
* @param portletContext the {@link PortletContext} (may not be {@code null})
* @param portletConfig the {@link PortletConfig} ({@code null} if not available)
* @see org.springframework.web.portlet.context.PortletApplicationContextUtils#initPortletPropertySources(
* org.springframework.core.env.MutablePropertySources, ServletContext, PortletContext, PortletConfig)
*/
public void initPropertySources(ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig) {
PortletApplicationContextUtils.initPortletPropertySources(getPropertySources(), servletContext, portletContext, portletConfig);
}
}