revised WebApplicationContext id determination; lazy logger initialization in ContextLoaderListener (SPR-5977)

This commit is contained in:
Juergen Hoeller
2009-08-08 00:48:55 +00:00
parent 33bb81b3ab
commit 6b824d9af7
5 changed files with 69 additions and 14 deletions

View File

@@ -327,20 +327,30 @@ public abstract class FrameworkPortlet extends GenericPortletBean
protected ApplicationContext createPortletApplicationContext(ApplicationContext parent)
throws BeansException {
Class<?> contextClass = getContextClass();
if (logger.isDebugEnabled()) {
logger.debug("Portlet with name '" + getPortletName() +
"' will try to create custom ApplicationContext context of class '" +
getContextClass().getName() + "'" + ", using parent context [" + parent + "]");
contextClass.getName() + "'" + ", using parent context [" + parent + "]");
}
if (!ConfigurablePortletApplicationContext.class.isAssignableFrom(getContextClass())) {
if (!ConfigurablePortletApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Fatal initialization error in portlet with name '" + getPortletName() +
"': custom ApplicationContext class [" + getContextClass().getName() +
"': custom ApplicationContext class [" + contextClass.getName() +
"] is not of type ConfigurablePortletApplicationContext");
}
ConfigurablePortletApplicationContext pac =
(ConfigurablePortletApplicationContext) BeanUtils.instantiateClass(getContextClass());
pac.setId(getPortletContext().getPortletContextName() + "." + getPortletName());
(ConfigurablePortletApplicationContext) BeanUtils.instantiateClass(contextClass);
// Assign the best possible id value.
String portletContextName = getPortletContext().getPortletContextName();
if (portletContextName != null) {
pac.setId(ConfigurablePortletApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + portletContextName + "." + getPortletName());
}
else {
pac.setId(ConfigurablePortletApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getPortletName());
}
pac.setParent(parent);
pac.setPortletContext(getPortletContext());
pac.setPortletConfig(getPortletConfig());

View File

@@ -43,6 +43,11 @@ import org.springframework.web.context.WebApplicationContext;
public interface ConfigurablePortletApplicationContext
extends WebApplicationContext, ConfigurableApplicationContext {
/**
* Prefix for ApplicationContext ids that refer to portlet name.
*/
String APPLICATION_CONTEXT_ID_PREFIX = WebApplicationContext.class.getName() + ":";
/**
* Name of the PortletContext environment bean in the factory.
* @see javax.portlet.PortletContext