Skip to content

Commit 8fb0f5c

Browse files
committed
FrameworkPortlet properly initializes StandardPortletEnvironment's property sources
Issue: SPR-11816
1 parent 5a8e470 commit 8fb0f5c

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/FrameworkPortlet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
import org.springframework.context.i18n.LocaleContext;
4242
import org.springframework.context.i18n.LocaleContextHolder;
4343
import org.springframework.context.i18n.SimpleLocaleContext;
44+
import org.springframework.core.env.ConfigurableEnvironment;
4445
import org.springframework.web.context.request.RequestAttributes;
4546
import org.springframework.web.context.request.RequestContextHolder;
4647
import org.springframework.web.portlet.context.ConfigurablePortletApplicationContext;
4748
import org.springframework.web.portlet.context.PortletApplicationContextUtils;
4849
import org.springframework.web.portlet.context.PortletRequestAttributes;
4950
import org.springframework.web.portlet.context.PortletRequestHandledEvent;
51+
import org.springframework.web.portlet.context.StandardPortletEnvironment;
5052
import org.springframework.web.portlet.context.XmlPortletApplicationContext;
5153

5254
/**
@@ -353,6 +355,14 @@ protected ApplicationContext createPortletApplicationContext(ApplicationContext
353355
pac.setConfigLocation(getContextConfigLocation());
354356
pac.addApplicationListener(new SourceFilteringListener(pac, this));
355357

358+
// The wac environment's #initPropertySources will be called in any case when the context
359+
// is refreshed; do it eagerly here to ensure portlet property sources are in place for
360+
// use in any post-processing or initialization that occurs below prior to #refresh
361+
ConfigurableEnvironment env = pac.getEnvironment();
362+
if (env instanceof StandardPortletEnvironment) {
363+
((StandardPortletEnvironment) env).initPropertySources(pac.getServletContext(), getPortletContext(), getPortletConfig());
364+
}
365+
356366
postProcessPortletApplicationContext(pac);
357367
pac.refresh();
358368

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/context/StandardPortletEnvironment.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,14 +31,15 @@
3131

3232
/**
3333
* {@link Environment} implementation to be used by {@code Servlet}-based web
34-
* applications. All Portlet-related {@code ApplicationContext} classes initialize an instance
35-
* by default.
34+
* applications. All Portlet-related {@code ApplicationContext} classes
35+
* initialize an instance by default.
3636
*
37-
* <p>Contributes {@code ServletContext}, {@code PortletContext}, {@code PortletConfig}
38-
* and JNDI-based {@link PropertySource} instances. See the
39-
* {@link #customizePropertySources} method for details.
37+
* <p>Contributes {@code ServletContext}, {@code PortletContext},
38+
* {@code PortletConfig} and JNDI-based {@link PropertySource} instances.
39+
* See the {@link #customizePropertySources} method for details.
4040
*
4141
* @author Chris Beams
42+
* @author Juergen Hoeller
4243
* @since 3.1
4344
* @see StandardEnvironment
4445
* @see StandardServletEnvironment
@@ -51,6 +52,7 @@ public class StandardPortletEnvironment extends StandardEnvironment {
5152
/** Portlet config init parameters property source name: {@value} */
5253
public static final String PORTLET_CONFIG_PROPERTY_SOURCE_NAME = "portletConfigInitParams";
5354

55+
5456
/**
5557
* Customize the set of property sources with those contributed by superclasses as
5658
* well as those appropriate for standard portlet-based environments:
@@ -88,4 +90,19 @@ protected void customizePropertySources(MutablePropertySources propertySources)
8890
super.customizePropertySources(propertySources);
8991
}
9092

93+
/**
94+
* Replace any {@linkplain
95+
* org.springframework.core.env.PropertySource.StubPropertySource stub property source}
96+
* instances acting as placeholders with real portlet context/config property sources
97+
* using the given parameters.
98+
* @param servletContext the {@link ServletContext} (may be {@code null})
99+
* @param portletContext the {@link PortletContext} (may not be {@code null})
100+
* @param portletConfig the {@link PortletConfig} ({@code null} if not available)
101+
* @see org.springframework.web.portlet.context.PortletApplicationContextUtils#initPortletPropertySources(
102+
* org.springframework.core.env.MutablePropertySources, ServletContext, PortletContext, PortletConfig)
103+
*/
104+
public void initPropertySources(ServletContext servletContext, PortletContext portletContext, PortletConfig portletConfig) {
105+
PortletApplicationContextUtils.initPortletPropertySources(getPropertySources(), servletContext, portletContext, portletConfig);
106+
}
107+
91108
}

0 commit comments

Comments
 (0)