diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java index 29f882ef67..a2e365035e 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java @@ -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(); diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StandardPortletEnvironment.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StandardPortletEnvironment.java index 7a2afb00b7..e6a8172b8b 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StandardPortletEnvironment.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StandardPortletEnvironment.java @@ -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. * - *
Contributes {@code ServletContext}, {@code PortletContext}, {@code PortletConfig} - * and JNDI-based {@link PropertySource} instances. See the - * {@link #customizePropertySources} method for details. + *
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); + } + }