Drop outdated BeanFactoryLocator / beanRefContext.xml mechanism
Issue: SPR-15154
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -28,13 +28,10 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.access.ContextSingletonBeanFactoryLocator;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
@@ -122,34 +119,6 @@ public class ContextLoader {
|
||||
*/
|
||||
public static final String GLOBAL_INITIALIZER_CLASSES_PARAM = "globalInitializerClasses";
|
||||
|
||||
/**
|
||||
* Optional servlet context parameter (i.e., "{@code locatorFactorySelector}")
|
||||
* used only when obtaining a parent context using the default implementation
|
||||
* of {@link #loadParentContext(ServletContext servletContext)}.
|
||||
* Specifies the 'selector' used in the
|
||||
* {@link ContextSingletonBeanFactoryLocator#getInstance(String selector)}
|
||||
* method call, which is used to obtain the BeanFactoryLocator instance from
|
||||
* which the parent context is obtained.
|
||||
* <p>The default is {@code classpath*:beanRefContext.xml},
|
||||
* matching the default applied for the
|
||||
* {@link ContextSingletonBeanFactoryLocator#getInstance()} method.
|
||||
* Supplying the "parentContextKey" parameter is sufficient in this case.
|
||||
*/
|
||||
public static final String LOCATOR_FACTORY_SELECTOR_PARAM = "locatorFactorySelector";
|
||||
|
||||
/**
|
||||
* Optional servlet context parameter (i.e., "{@code parentContextKey}")
|
||||
* used only when obtaining a parent context using the default implementation
|
||||
* of {@link #loadParentContext(ServletContext servletContext)}.
|
||||
* Specifies the 'factoryKey' used in the
|
||||
* {@link BeanFactoryLocator#useBeanFactory(String factoryKey)} method call,
|
||||
* obtaining the parent application context from the BeanFactoryLocator instance.
|
||||
* <p>Supplying this "parentContextKey" parameter is sufficient when relying
|
||||
* on the default {@code classpath*:beanRefContext.xml} selector for
|
||||
* candidate factory references.
|
||||
*/
|
||||
public static final String LOCATOR_FACTORY_KEY_PARAM = "parentContextKey";
|
||||
|
||||
/**
|
||||
* Any number of these characters are considered delimiters between
|
||||
* multiple values in a single init-param String value.
|
||||
@@ -197,12 +166,6 @@ public class ContextLoader {
|
||||
*/
|
||||
private WebApplicationContext context;
|
||||
|
||||
/**
|
||||
* Holds BeanFactoryReference when loading parent factory via
|
||||
* ContextSingletonBeanFactoryLocator.
|
||||
*/
|
||||
private BeanFactoryReference parentContextRef;
|
||||
|
||||
/** Actual ApplicationContextInitializer instances to apply to the context */
|
||||
private final List<ApplicationContextInitializer<ConfigurableApplicationContext>> contextInitializers =
|
||||
new ArrayList<>();
|
||||
@@ -535,34 +498,12 @@ public class ContextLoader {
|
||||
* alternately to also share the same parent context that is visible to
|
||||
* EJBs. For pure web applications, there is usually no need to worry about
|
||||
* having a parent context to the root web application context.
|
||||
* <p>The default implementation uses
|
||||
* {@link org.springframework.context.access.ContextSingletonBeanFactoryLocator},
|
||||
* configured via {@link #LOCATOR_FACTORY_SELECTOR_PARAM} and
|
||||
* {@link #LOCATOR_FACTORY_KEY_PARAM}, to load a parent context
|
||||
* which will be shared by all other users of ContextsingletonBeanFactoryLocator
|
||||
* which also use the same configuration parameters.
|
||||
* <p>The default implementation simply returns {@code null}, as of 5.0.
|
||||
* @param servletContext current servlet context
|
||||
* @return the parent application context, or {@code null} if none
|
||||
* @see org.springframework.context.access.ContextSingletonBeanFactoryLocator
|
||||
*/
|
||||
protected ApplicationContext loadParentContext(ServletContext servletContext) {
|
||||
ApplicationContext parentContext = null;
|
||||
String locatorFactorySelector = servletContext.getInitParameter(LOCATOR_FACTORY_SELECTOR_PARAM);
|
||||
String parentContextKey = servletContext.getInitParameter(LOCATOR_FACTORY_KEY_PARAM);
|
||||
|
||||
if (parentContextKey != null) {
|
||||
// locatorFactorySelector may be null, indicating the default "classpath*:beanRefContext.xml"
|
||||
BeanFactoryLocator locator = ContextSingletonBeanFactoryLocator.getInstance(locatorFactorySelector);
|
||||
Log logger = LogFactory.getLog(ContextLoader.class);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Getting parent context definition: using parent context key of '" +
|
||||
parentContextKey + "' with BeanFactoryLocator");
|
||||
}
|
||||
this.parentContextRef = locator.useBeanFactory(parentContextKey);
|
||||
parentContext = (ApplicationContext) this.parentContextRef.getFactory();
|
||||
}
|
||||
|
||||
return parentContext;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -590,9 +531,6 @@ public class ContextLoader {
|
||||
currentContextPerThread.remove(ccl);
|
||||
}
|
||||
servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
|
||||
if (this.parentContextRef != null) {
|
||||
this.parentContextRef.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 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,11 +16,14 @@
|
||||
|
||||
package org.springframework.web.jsf.el;
|
||||
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.util.Iterator;
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELException;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.PropertyNotWritableException;
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.access.el.SpringBeanELResolver;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.jsf.FacesContextUtils;
|
||||
|
||||
@@ -64,18 +67,72 @@ import org.springframework.web.jsf.FacesContextUtils;
|
||||
* @see WebApplicationContextFacesELResolver
|
||||
* @see org.springframework.web.jsf.FacesContextUtils#getRequiredWebApplicationContext
|
||||
*/
|
||||
public class SpringBeanFacesELResolver extends SpringBeanELResolver {
|
||||
public class SpringBeanFacesELResolver extends ELResolver {
|
||||
|
||||
/**
|
||||
* This implementation delegates to {@link #getWebApplicationContext}.
|
||||
* Can be overridden to provide an arbitrary BeanFactory reference to resolve
|
||||
* against; usually, this will be a full Spring ApplicationContext.
|
||||
* @param elContext the current JSF ELContext
|
||||
* @return the Spring BeanFactory (never {@code null})
|
||||
*/
|
||||
@Override
|
||||
protected BeanFactory getBeanFactory(ELContext elContext) {
|
||||
return getWebApplicationContext(elContext);
|
||||
public Object getValue(ELContext elContext, Object base, Object property) throws ELException {
|
||||
if (base == null) {
|
||||
String beanName = property.toString();
|
||||
WebApplicationContext wac = getWebApplicationContext(elContext);
|
||||
if (wac.containsBean(beanName)) {
|
||||
elContext.setPropertyResolved(true);
|
||||
return wac.getBean(beanName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getType(ELContext elContext, Object base, Object property) throws ELException {
|
||||
if (base == null) {
|
||||
String beanName = property.toString();
|
||||
WebApplicationContext wac = getWebApplicationContext(elContext);
|
||||
if (wac.containsBean(beanName)) {
|
||||
elContext.setPropertyResolved(true);
|
||||
return wac.getType(beanName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(ELContext elContext, Object base, Object property, Object value) throws ELException {
|
||||
if (base == null) {
|
||||
String beanName = property.toString();
|
||||
WebApplicationContext wac = getWebApplicationContext(elContext);
|
||||
if (wac.containsBean(beanName)) {
|
||||
if (value == wac.getBean(beanName)) {
|
||||
// Setting the bean reference to the same value is alright - can simply be ignored...
|
||||
elContext.setPropertyResolved(true);
|
||||
}
|
||||
else {
|
||||
throw new PropertyNotWritableException(
|
||||
"Variable '" + beanName + "' refers to a Spring bean which by definition is not writable");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly(ELContext elContext, Object base, Object property) throws ELException {
|
||||
if (base == null) {
|
||||
String beanName = property.toString();
|
||||
WebApplicationContext wac = getWebApplicationContext(elContext);
|
||||
if (wac.containsBean(beanName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext elContext, Object base) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getCommonPropertyType(ELContext elContext, Object base) {
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user