Merge branch '3.2.x' into master
Conflicts: gradle.properties spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java
This commit is contained in:
@@ -699,7 +699,7 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
||||
return nestedBw.getPropertyValue(tokens);
|
||||
}
|
||||
|
||||
private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
|
||||
private Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
|
||||
String propertyName = tokens.canonicalName;
|
||||
String actualName = tokens.actualName;
|
||||
PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -107,9 +107,6 @@ public class CachedIntrospectionResults {
|
||||
* @param classLoader the ClassLoader to clear the cache for
|
||||
*/
|
||||
public static void clearClassLoader(ClassLoader classLoader) {
|
||||
if (classLoader == null) {
|
||||
return;
|
||||
}
|
||||
synchronized (classCache) {
|
||||
for (Iterator<Class> it = classCache.keySet().iterator(); it.hasNext();) {
|
||||
Class beanClass = it.next();
|
||||
@@ -199,12 +196,12 @@ public class CachedIntrospectionResults {
|
||||
* @param parent the parent ClassLoader to check for
|
||||
*/
|
||||
private static boolean isUnderneathClassLoader(ClassLoader candidate, ClassLoader parent) {
|
||||
if (candidate == null) {
|
||||
return false;
|
||||
}
|
||||
if (candidate == parent) {
|
||||
return true;
|
||||
}
|
||||
if (candidate == null) {
|
||||
return false;
|
||||
}
|
||||
ClassLoader classLoaderToCheck = candidate;
|
||||
while (classLoaderToCheck != null) {
|
||||
classLoaderToCheck = classLoaderToCheck.getParent();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -56,7 +56,7 @@ import static org.springframework.beans.PropertyDescriptorUtils.*;
|
||||
* this.foo = foo;
|
||||
* return this;
|
||||
* }
|
||||
* }</pre>
|
||||
* }}</pre>
|
||||
* The standard JavaBeans {@code Introspector} will discover the {@code getFoo} read
|
||||
* method, but will bypass the {@code #setFoo(Foo)} write method, because its non-void
|
||||
* returning signature does not comply with the JavaBeans specification.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,6 +23,9 @@ package org.springframework.beans;
|
||||
* algorithm (including delegation to {@link java.beans.PropertyEditor} and
|
||||
* {@link org.springframework.core.convert.ConversionService}) underneath.
|
||||
*
|
||||
* <p><b>Note:</b> Due to its reliance on {@link java.beans.PropertyEditor PropertyEditors},
|
||||
* SimpleTypeConverter is <em>not</em> thread-safe. Use a separate instance for each thread.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
* @see BeanWrapperImpl
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -24,6 +24,10 @@ import org.springframework.core.MethodParameter;
|
||||
* Interface that defines type conversion methods. Typically (but not necessarily)
|
||||
* implemented in conjunction with the {@link PropertyEditorRegistry} interface.
|
||||
*
|
||||
* <p><b>Note:</b> Since TypeConverter implementations are typically based on
|
||||
* {@link java.beans.PropertyEditor PropertyEditors} which aren't thread-safe,
|
||||
* TypeConverters themselves are <em>not</em> to be considered as thread-safe either.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
* @see SimpleTypeConverter
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.beans.factory;
|
||||
/**
|
||||
* Marker superinterface indicating that a bean is eligible to be
|
||||
* notified by the Spring container of a particular framework object
|
||||
* through a callback-style method. Actual method signature is
|
||||
* through a callback-style method. Actual method signature is
|
||||
* determined by individual subinterfaces, but should typically
|
||||
* consist of just one void-returning method that accepts a single
|
||||
* argument.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -143,7 +143,7 @@ public interface BeanFactory {
|
||||
* is {@code Object.class}, this method will succeed whatever the class of the
|
||||
* returned instance.
|
||||
* @return an instance of the bean
|
||||
* @throws NoSuchBeanDefinitionException if there's no such bean definition
|
||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||
* @throws BeanNotOfRequiredTypeException if the bean is not of the required type
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
@@ -158,7 +158,8 @@ public interface BeanFactory {
|
||||
* of the given type. For more extensive retrieval operations across sets of beans,
|
||||
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
|
||||
* @return an instance of the single bean matching the required type
|
||||
* @throws NoSuchBeanDefinitionException if there is not exactly one matching bean found
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @since 3.0
|
||||
* @see ListableBeanFactory
|
||||
*/
|
||||
@@ -172,7 +173,7 @@ public interface BeanFactory {
|
||||
* @param args arguments to use if creating a prototype using explicit arguments to a
|
||||
* static factory method. It is invalid to use a non-null args value in any other case.
|
||||
* @return an instance of the bean
|
||||
* @throws NoSuchBeanDefinitionException if there's no such bean definition
|
||||
* @throws NoSuchBeanDefinitionException if there is no such bean definition
|
||||
* @throws BeanDefinitionStoreException if arguments have been given but
|
||||
* the affected bean isn't a prototype
|
||||
* @throws BeansException if the bean could not be created
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -310,20 +310,15 @@ public abstract class BeanFactoryUtils {
|
||||
* @param lbf the bean factory
|
||||
* @param type type of bean to match
|
||||
* @return the matching bean instance
|
||||
* @throws NoSuchBeanDefinitionException
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static <T> T beanOfTypeIncludingAncestors(ListableBeanFactory lbf, Class<T> type)
|
||||
throws BeansException {
|
||||
|
||||
Map<String, T> beansOfType = beansOfTypeIncludingAncestors(lbf, type);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
else {
|
||||
throw new NoSuchBeanDefinitionException(type, "expected single bean but found " + beansOfType.size());
|
||||
}
|
||||
return uniqueBean(type, beansOfType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,8 +346,8 @@ public abstract class BeanFactoryUtils {
|
||||
* eagerly initialized to determine their type: So be aware that passing in "true"
|
||||
* for this flag will initialize FactoryBeans and "factory-bean" references.
|
||||
* @return the matching bean instance
|
||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static <T> T beanOfTypeIncludingAncestors(
|
||||
@@ -360,12 +355,7 @@ public abstract class BeanFactoryUtils {
|
||||
throws BeansException {
|
||||
|
||||
Map<String, T> beansOfType = beansOfTypeIncludingAncestors(lbf, type, includeNonSingletons, allowEagerInit);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
else {
|
||||
throw new NoSuchBeanDefinitionException(type, "expected single bean but found " + beansOfType.size());
|
||||
}
|
||||
return uniqueBean(type, beansOfType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,19 +370,14 @@ public abstract class BeanFactoryUtils {
|
||||
* @param lbf the bean factory
|
||||
* @param type type of bean to match
|
||||
* @return the matching bean instance
|
||||
* @throws NoSuchBeanDefinitionException
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static <T> T beanOfType(ListableBeanFactory lbf, Class<T> type) throws BeansException {
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
Map<String, T> beansOfType = lbf.getBeansOfType(type);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
}
|
||||
else {
|
||||
throw new NoSuchBeanDefinitionException(type, "expected single bean but found " + beansOfType.size());
|
||||
}
|
||||
return uniqueBean(type, beansOfType);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,8 +400,8 @@ public abstract class BeanFactoryUtils {
|
||||
* eagerly initialized to determine their type: So be aware that passing in "true"
|
||||
* for this flag will initialize FactoryBeans and "factory-bean" references.
|
||||
* @return the matching bean instance
|
||||
* @throws org.springframework.beans.factory.NoSuchBeanDefinitionException
|
||||
* if 0 or more than 1 beans of the given type were found
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
* @throws BeansException if the bean could not be created
|
||||
*/
|
||||
public static <T> T beanOfType(
|
||||
@@ -425,11 +410,27 @@ public abstract class BeanFactoryUtils {
|
||||
|
||||
Assert.notNull(lbf, "ListableBeanFactory must not be null");
|
||||
Map<String, T> beansOfType = lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit);
|
||||
if (beansOfType.size() == 1) {
|
||||
return beansOfType.values().iterator().next();
|
||||
return uniqueBean(type, beansOfType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a unique bean for the given type from the given Map of matching beans.
|
||||
* @param type type of bean to match
|
||||
* @param matchingBeans all matching beans found
|
||||
* @return the unique bean instance
|
||||
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
|
||||
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
|
||||
*/
|
||||
private static <T> T uniqueBean(Class<T> type, Map<String, T> matchingBeans) {
|
||||
int nrFound = matchingBeans.size();
|
||||
if (nrFound == 1) {
|
||||
return matchingBeans.values().iterator().next();
|
||||
}
|
||||
else if (nrFound > 1) {
|
||||
throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet());
|
||||
}
|
||||
else {
|
||||
throw new NoSuchBeanDefinitionException(type, "expected single bean but found " + beansOfType.size());
|
||||
throw new NoSuchBeanDefinitionException(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -20,11 +20,13 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Exception thrown when a {@code BeanFactory} is asked for a bean
|
||||
* instance for which it cannot find a definition.
|
||||
* Exception thrown when a {@code BeanFactory} is asked for a bean instance
|
||||
* for which it cannot find a definition.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @see BeanFactory#getBean(String)
|
||||
* @see BeanFactory#getBean(Class)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class NoSuchBeanDefinitionException extends BeansException {
|
||||
@@ -60,7 +62,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
* @param type required type of the missing bean
|
||||
*/
|
||||
public NoSuchBeanDefinitionException(Class<?> type) {
|
||||
super("No unique bean of type [" + type.getName() + "] is defined");
|
||||
super("No qualifying bean of type [" + type.getName() + "] is defined");
|
||||
this.beanType = type;
|
||||
}
|
||||
|
||||
@@ -70,7 +72,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
* @param message detailed message describing the problem
|
||||
*/
|
||||
public NoSuchBeanDefinitionException(Class<?> type, String message) {
|
||||
super("No unique bean of type [" + type.getName() + "] is defined: " + message);
|
||||
super("No qualifying bean of type [" + type.getName() + "] is defined: " + message);
|
||||
this.beanType = type;
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
* @param message detailed message describing the problem
|
||||
*/
|
||||
public NoSuchBeanDefinitionException(Class<?> type, String dependencyDescription, String message) {
|
||||
super("No matching bean of type [" + type.getName() + "] found for dependency" +
|
||||
super("No qualifying bean of type [" + type.getName() + "] found for dependency" +
|
||||
(StringUtils.hasLength(dependencyDescription) ? " [" + dependencyDescription + "]" : "") +
|
||||
": " + message);
|
||||
this.beanType = type;
|
||||
@@ -89,19 +91,26 @@ public class NoSuchBeanDefinitionException extends BeansException {
|
||||
|
||||
|
||||
/**
|
||||
* Return the name of the missing bean, if it was a lookup <em>by name</em>
|
||||
* that failed.
|
||||
* Return the name of the missing bean, if it was a lookup <em>by name</em> that failed.
|
||||
*/
|
||||
public String getBeanName() {
|
||||
return this.beanName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required type of the missing bean, if it was a lookup
|
||||
* <em>by type</em> that failed.
|
||||
* Return the required type of the missing bean, if it was a lookup <em>by type</em> that failed.
|
||||
*/
|
||||
public Class<?> getBeanType() {
|
||||
return this.beanType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of beans found when only one matching bean was expected.
|
||||
* For a regular NoSuchBeanDefinitionException, this will always be 0.
|
||||
* @see NoUniqueBeanDefinitionException
|
||||
*/
|
||||
public int getNumberOfBeansFound() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans.factory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Exception thrown when a {@code BeanFactory} is asked for a bean instance for which
|
||||
* multiple matching candidates have been found when only one matching bean was expected.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.2.1
|
||||
* @see BeanFactory#getBean(Class)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionException {
|
||||
|
||||
private int numberOfBeansFound;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@code NoUniqueBeanDefinitionException}.
|
||||
* @param type required type of the non-unique bean
|
||||
* @param numberOfBeansFound the number of matching beans
|
||||
* @param message detailed message describing the problem
|
||||
*/
|
||||
public NoUniqueBeanDefinitionException(Class<?> type, int numberOfBeansFound, String message) {
|
||||
super(type, message);
|
||||
this.numberOfBeansFound = numberOfBeansFound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code NoUniqueBeanDefinitionException}.
|
||||
* @param type required type of the non-unique bean
|
||||
* @param beanNamesFound the names of all matching beans (as a Collection)
|
||||
*/
|
||||
public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) {
|
||||
this(type, beanNamesFound.size(), "expected single matching bean but found " + beanNamesFound.size() + ": " +
|
||||
StringUtils.collectionToCommaDelimitedString(beanNamesFound));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code NoUniqueBeanDefinitionException}.
|
||||
* @param type required type of the non-unique bean
|
||||
* @param beanNamesFound the names of all matching beans (as an array)
|
||||
*/
|
||||
public NoUniqueBeanDefinitionException(Class<?> type, String... beanNamesFound) {
|
||||
this(type, Arrays.asList(beanNamesFound));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the number of beans found when only one matching bean was expected.
|
||||
* For a NoUniqueBeanDefinitionException, this will usually be higher than 1.
|
||||
* @see #getBeanType()
|
||||
*/
|
||||
@Override
|
||||
public int getNumberOfBeansFound() {
|
||||
return this.numberOfBeansFound;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,7 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory.access;
|
||||
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
/**
|
||||
@@ -49,11 +48,10 @@ public interface BeanFactoryReference {
|
||||
* <p>In an EJB usage scenario this would normally be called from
|
||||
* {@code ejbRemove()} and {@code ejbPassivate()}.
|
||||
* <p>This is safe to call multiple times.
|
||||
* @throws FatalBeanException if the {@code BeanFactory} cannot be released
|
||||
* @see BeanFactoryLocator
|
||||
* @see org.springframework.context.access.ContextBeanFactoryReference
|
||||
* @see org.springframework.context.ConfigurableApplicationContext#close()
|
||||
*/
|
||||
void release() throws FatalBeanException;
|
||||
void release();
|
||||
|
||||
}
|
||||
|
||||
@@ -196,11 +196,11 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
|
||||
@@ -109,11 +109,11 @@ public class InitDestroyAnnotationBeanPostProcessor
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -123,11 +123,11 @@ public class RequiredAnnotationBeanPostProcessor extends InstantiationAwareBeanP
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -116,11 +116,11 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, BeanCla
|
||||
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
return this.order;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -80,7 +80,7 @@ public class RuntimeBeanNameReference implements BeanReference {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '<' + getBeanName() + '>';
|
||||
return '<' + getBeanName() + '>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class RuntimeBeanReference implements BeanReference {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '<' + getBeanName() + '>';
|
||||
return '<' + getBeanName() + '>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -27,7 +27,6 @@ import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.FatalBeanException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
@@ -364,12 +363,12 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
|
||||
try {
|
||||
String beanName = tryGetBeanName(args);
|
||||
if (StringUtils.hasLength(beanName)) {
|
||||
// Service locator for a specific bean name.
|
||||
// Service locator for a specific bean name
|
||||
return beanFactory.getBean(beanName, serviceLocatorMethodReturnType);
|
||||
}
|
||||
else {
|
||||
// Service locator for a bean type.
|
||||
return BeanFactoryUtils.beanOfTypeIncludingAncestors(beanFactory, serviceLocatorMethodReturnType);
|
||||
// Service locator for a bean type
|
||||
return beanFactory.getBean(serviceLocatorMethodReturnType);
|
||||
}
|
||||
}
|
||||
catch (BeansException ex) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -572,28 +572,30 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) {
|
||||
Class beanClass;
|
||||
if (mbd.getFactoryMethodName() != null) {
|
||||
beanClass = getTypeForFactoryMethod(beanName, mbd, typesToMatch);
|
||||
}
|
||||
else {
|
||||
beanClass = resolveBeanClass(mbd, beanName, typesToMatch);
|
||||
protected Class<?> predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) {
|
||||
Class<?> targetType = mbd.getTargetType();
|
||||
if (targetType == null) {
|
||||
targetType = (mbd.getFactoryMethodName() != null ? getTypeForFactoryMethod(beanName, mbd, typesToMatch) :
|
||||
resolveBeanClass(mbd, beanName, typesToMatch));
|
||||
if (ObjectUtils.isEmpty(typesToMatch) || getTempClassLoader() == null) {
|
||||
mbd.setTargetType(targetType);
|
||||
}
|
||||
}
|
||||
// Apply SmartInstantiationAwareBeanPostProcessors to predict the
|
||||
// eventual type after a before-instantiation shortcut.
|
||||
if (beanClass != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
|
||||
if (targetType != null && !mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
|
||||
for (BeanPostProcessor bp : getBeanPostProcessors()) {
|
||||
if (bp instanceof SmartInstantiationAwareBeanPostProcessor) {
|
||||
SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
|
||||
Class processedType = ibp.predictBeanType(beanClass, beanName);
|
||||
if (processedType != null) {
|
||||
return processedType;
|
||||
Class predicted = ibp.predictBeanType(targetType, beanName);
|
||||
if (predicted != null && (typesToMatch.length != 1 || !FactoryBean.class.equals(typesToMatch[0]) ||
|
||||
FactoryBean.class.isAssignableFrom(predicted))) {
|
||||
return predicted;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return beanClass;
|
||||
return targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -610,8 +612,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
* @return the type for the bean if determinable, or {@code null} else
|
||||
* @see #createBean
|
||||
*/
|
||||
protected Class getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class[] typesToMatch) {
|
||||
Class factoryClass;
|
||||
protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class[] typesToMatch) {
|
||||
Class<?> factoryClass;
|
||||
boolean isStatic = true;
|
||||
|
||||
String factoryBeanName = mbd.getFactoryBeanName();
|
||||
@@ -685,7 +687,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
if (factoryBeanName != null && factoryMethodName != null) {
|
||||
// Try to obtain the FactoryBean's object type without instantiating it at all.
|
||||
BeanDefinition fbDef = getBeanDefinition(factoryBeanName);
|
||||
if (fbDef instanceof AbstractBeanDefinition) {
|
||||
if (fbDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) fbDef).hasBeanClass()) {
|
||||
Class<?> fbClass = ((AbstractBeanDefinition) fbDef).getBeanClass();
|
||||
if (ClassUtils.isCglibProxyClass(fbClass)) {
|
||||
// CGLIB subclass methods hide generic parameters. look at the superclass.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -497,18 +497,21 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
// Retrieve corresponding bean definition.
|
||||
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
|
||||
|
||||
Class[] typesToMatch = (FactoryBean.class.equals(typeToMatch) ?
|
||||
new Class[] {typeToMatch} : new Class[] {FactoryBean.class, typeToMatch});
|
||||
|
||||
// Check decorated bean definition, if any: We assume it'll be easier
|
||||
// to determine the decorated bean's type than the proxy's type.
|
||||
BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
|
||||
if (dbd != null && !BeanFactoryUtils.isFactoryDereference(name)) {
|
||||
RootBeanDefinition tbd = getMergedBeanDefinition(dbd.getBeanName(), dbd.getBeanDefinition(), mbd);
|
||||
Class<?> targetClass = predictBeanType(dbd.getBeanName(), tbd, FactoryBean.class, typeToMatch);
|
||||
Class<?> targetClass = predictBeanType(dbd.getBeanName(), tbd, typesToMatch);
|
||||
if (targetClass != null && !FactoryBean.class.isAssignableFrom(targetClass)) {
|
||||
return typeToMatch.isAssignableFrom(targetClass);
|
||||
}
|
||||
}
|
||||
|
||||
Class<?> beanClass = predictBeanType(beanName, mbd, FactoryBean.class, typeToMatch);
|
||||
Class<?> beanClass = predictBeanType(beanName, mbd, typesToMatch);
|
||||
if (beanClass == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -746,6 +749,9 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
public String resolveEmbeddedValue(String value) {
|
||||
String result = value;
|
||||
for (StringValueResolver resolver : this.embeddedValueResolvers) {
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
result = resolver.resolveStringValue(result);
|
||||
}
|
||||
return result;
|
||||
@@ -1329,9 +1335,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
* @param mbd the corresponding bean definition
|
||||
*/
|
||||
protected boolean isFactoryBean(String beanName, RootBeanDefinition mbd) {
|
||||
Class<?> predictedType = predictBeanType(beanName, mbd, FactoryBean.class);
|
||||
return (predictedType != null && FactoryBean.class.isAssignableFrom(predictedType)) ||
|
||||
(mbd.hasBeanClass() && FactoryBean.class.isAssignableFrom(mbd.getBeanClass()));
|
||||
Class<?> beanClass = predictBeanType(beanName, mbd, FactoryBean.class);
|
||||
return (beanClass != null && FactoryBean.class.isAssignableFrom(beanClass));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Juergen Hoeller
|
||||
* @since 2.0
|
||||
*/
|
||||
public class BeanDefinitionBuilder {
|
||||
public class BeanDefinitionBuilder {
|
||||
|
||||
/**
|
||||
* Create a new {@code BeanDefinitionBuilder} used to construct a {@link GenericBeanDefinition}.
|
||||
|
||||
@@ -888,4 +888,4 @@ class ConstructorResolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -50,6 +50,7 @@ import org.springframework.beans.factory.BeanFactoryUtils;
|
||||
import org.springframework.beans.factory.CannotLoadBeanClassException;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
import org.springframework.beans.factory.SmartFactoryBean;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
@@ -89,6 +90,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Sam Brannen
|
||||
* @author Costin Leau
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
* @since 16 April 2001
|
||||
* @see StaticListableBeanFactory
|
||||
* @see PropertiesBeanDefinitionReader
|
||||
@@ -270,12 +272,28 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
if (beanNames.length == 1) {
|
||||
return getBean(beanNames[0], requiredType);
|
||||
}
|
||||
else if (beanNames.length == 0 && getParentBeanFactory() != null) {
|
||||
else if (beanNames.length > 1) {
|
||||
T primaryBean = null;
|
||||
for (String beanName : beanNames) {
|
||||
T beanInstance = getBean(beanName, requiredType);
|
||||
if (isPrimary(beanName, beanInstance)) {
|
||||
if (primaryBean != null) {
|
||||
throw new NoUniqueBeanDefinitionException(requiredType, beanNames.length,
|
||||
"more than one 'primary' bean found of required type: " + Arrays.asList(beanNames));
|
||||
}
|
||||
primaryBean = beanInstance;
|
||||
}
|
||||
}
|
||||
if (primaryBean != null) {
|
||||
return primaryBean;
|
||||
}
|
||||
throw new NoUniqueBeanDefinitionException(requiredType, beanNames);
|
||||
}
|
||||
else if (getParentBeanFactory() != null) {
|
||||
return getParentBeanFactory().getBean(requiredType);
|
||||
}
|
||||
else {
|
||||
throw new NoSuchBeanDefinitionException(requiredType, "expected single bean but found " +
|
||||
beanNames.length + ": " + StringUtils.arrayToCommaDelimitedString(beanNames));
|
||||
throw new NoSuchBeanDefinitionException(requiredType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -718,7 +736,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public Object resolveDependency(DependencyDescriptor descriptor, String beanName,
|
||||
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
|
||||
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
|
||||
|
||||
descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());
|
||||
if (descriptor.getDependencyType().equals(ObjectFactory.class)) {
|
||||
@@ -733,7 +751,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
}
|
||||
|
||||
protected Object doResolveDependency(DependencyDescriptor descriptor, Class<?> type, String beanName,
|
||||
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
|
||||
Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {
|
||||
|
||||
Object value = getAutowireCandidateResolver().getSuggestedValue(descriptor);
|
||||
if (value != null) {
|
||||
@@ -823,8 +841,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
if (matchingBeans.size() > 1) {
|
||||
String primaryBeanName = determinePrimaryCandidate(matchingBeans, descriptor);
|
||||
if (primaryBeanName == null) {
|
||||
throw new NoSuchBeanDefinitionException(type, "expected single matching bean but found " +
|
||||
matchingBeans.size() + ": " + matchingBeans.keySet());
|
||||
throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet());
|
||||
}
|
||||
if (autowiredBeanNames != null) {
|
||||
autowiredBeanNames.add(primaryBeanName);
|
||||
@@ -895,7 +912,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
boolean candidateLocal = containsBeanDefinition(candidateBeanName);
|
||||
boolean primaryLocal = containsBeanDefinition(primaryBeanName);
|
||||
if (candidateLocal == primaryLocal) {
|
||||
throw new NoSuchBeanDefinitionException(descriptor.getDependencyType(),
|
||||
throw new NoUniqueBeanDefinitionException(descriptor.getDependencyType(), candidateBeans.size(),
|
||||
"more than one 'primary' bean found among candidates: " + candidateBeans.keySet());
|
||||
}
|
||||
else if (candidateLocal && !primaryLocal) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -61,6 +61,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
|
||||
private static final String CLOSE_METHOD_NAME = "close";
|
||||
|
||||
private static final String SHUTDOWN_METHOD_NAME = "shutdown";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);
|
||||
|
||||
private static Class closeableInterface;
|
||||
@@ -176,7 +178,12 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
|
||||
return bean.getClass().getMethod(CLOSE_METHOD_NAME).getName();
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
// no candidate destroy method found
|
||||
try {
|
||||
return bean.getClass().getMethod(SHUTDOWN_METHOD_NAME).getName();
|
||||
}
|
||||
catch (NoSuchMethodException ex2) {
|
||||
// no candidate destroy method found
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -165,7 +165,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader
|
||||
* class can still override this.
|
||||
* <p>Strictly speaking, the rule that a default parent setting does
|
||||
* not apply to a bean definition that carries a class is there for
|
||||
* backwards compatiblity reasons. It still matches the typical use case.
|
||||
* backwards compatibility reasons. It still matches the typical use case.
|
||||
*/
|
||||
public void setDefaultParentBean(String defaultParentBean) {
|
||||
this.defaultParentBean = defaultParentBean;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -61,8 +61,12 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
|
||||
boolean allowCaching = true;
|
||||
|
||||
private volatile Class<?> targetType;
|
||||
|
||||
boolean isFactoryMethodUnique = false;
|
||||
|
||||
final Object constructorArgumentLock = new Object();
|
||||
|
||||
/** Package-visible field for caching the resolved constructor or factory method */
|
||||
Object resolvedConstructorOrFactoryMethod;
|
||||
|
||||
@@ -75,15 +79,13 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
/** Package-visible field for caching partly prepared constructor arguments */
|
||||
Object[] preparedConstructorArguments;
|
||||
|
||||
final Object constructorArgumentLock = new Object();
|
||||
|
||||
/** Package-visible field that indicates a before-instantiation post-processor having kicked in */
|
||||
volatile Boolean beforeInstantiationResolved;
|
||||
final Object postProcessingLock = new Object();
|
||||
|
||||
/** Package-visible field that indicates MergedBeanDefinitionPostProcessor having been applied */
|
||||
boolean postProcessed = false;
|
||||
|
||||
final Object postProcessingLock = new Object();
|
||||
/** Package-visible field that indicates a before-instantiation post-processor having kicked in */
|
||||
volatile Boolean beforeInstantiationResolved;
|
||||
|
||||
|
||||
/**
|
||||
@@ -236,6 +238,8 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
if (original instanceof RootBeanDefinition) {
|
||||
RootBeanDefinition originalRbd = (RootBeanDefinition) original;
|
||||
this.decoratedDefinition = originalRbd.decoratedDefinition;
|
||||
this.allowCaching = originalRbd.allowCaching;
|
||||
this.targetType = originalRbd.targetType;
|
||||
this.isFactoryMethodUnique = originalRbd.isFactoryMethodUnique;
|
||||
}
|
||||
}
|
||||
@@ -251,6 +255,21 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the target type of this bean definition, if known in advance.
|
||||
*/
|
||||
public void setTargetType(Class<?> targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the target type of this bean definition, if known
|
||||
* (either specified in advance or resolved on first instantiation).
|
||||
*/
|
||||
public Class<?> getTargetType() {
|
||||
return this.targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a factory method name that refers to a non-overloaded method.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,6 +31,7 @@ import org.springframework.beans.factory.BeanNotOfRequiredTypeException;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||
import org.springframework.beans.factory.SmartFactoryBean;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -117,8 +118,11 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
if (beanNames.length == 1) {
|
||||
return getBean(beanNames[0], requiredType);
|
||||
}
|
||||
else if (beanNames.length > 1) {
|
||||
throw new NoUniqueBeanDefinitionException(requiredType, beanNames);
|
||||
}
|
||||
else {
|
||||
throw new NoSuchBeanDefinitionException(requiredType, "expected single bean but found " + beanNames.length);
|
||||
throw new NoSuchBeanDefinitionException(requiredType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -30,14 +30,13 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Convenient base class for configurers that can perform Dependency Injection
|
||||
* Convenient base class for bean configurers that can perform Dependency Injection
|
||||
* on objects (however they may be created). Typically subclassed by AspectJ aspects.
|
||||
*
|
||||
* <p>Subclasses may also need a custom metadata resolution strategy, in the
|
||||
* {@link BeanWiringInfoResolver} interface. The default implementation looks
|
||||
* for a bean with the same name as the fully-qualified class name. (This is
|
||||
* the default name of the bean in a Spring XML file if the '{@code id}'
|
||||
* attribute is not used.)
|
||||
* {@link BeanWiringInfoResolver} interface. The default implementation looks for
|
||||
* a bean with the same name as the fully-qualified class name. (This is the default
|
||||
* name of the bean in a Spring XML file if the '{@code id}' attribute is not used.)
|
||||
|
||||
* @author Rob Harrop
|
||||
* @author Rod Johnson
|
||||
@@ -47,7 +46,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @see #setBeanWiringInfoResolver
|
||||
* @see ClassNameBeanWiringInfoResolver
|
||||
*/
|
||||
public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean, DisposableBean {
|
||||
|
||||
/** Logger available to subclasses */
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
@@ -113,8 +112,7 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean
|
||||
/**
|
||||
* Configure the bean instance.
|
||||
* <p>Subclasses can override this to provide custom configuration logic.
|
||||
* Typically called by an aspect, for all bean instances matched by a
|
||||
* pointcut.
|
||||
* Typically called by an aspect, for all bean instances matched by a pointcut.
|
||||
* @param beanInstance the bean instance to configure (must <b>not</b> be {@code null})
|
||||
*/
|
||||
public void configureBean(Object beanInstance) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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,11 @@
|
||||
|
||||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* SPI for parsing an XML document that contains Spring bean definitions.
|
||||
* Used by XmlBeanDefinitionReader for actually parsing a DOM document.
|
||||
@@ -38,20 +38,21 @@ import org.w3c.dom.Document;
|
||||
public interface BeanDefinitionDocumentReader {
|
||||
|
||||
/**
|
||||
* Read bean definitions from the given DOM document,
|
||||
* and register them with the given bean factory.
|
||||
* Set the Environment to use when reading bean definitions.
|
||||
* <p>Used for evaluating profile information to determine whether a
|
||||
* {@code <beans/>} document/element should be included or ignored.
|
||||
*/
|
||||
void setEnvironment(Environment environment);
|
||||
|
||||
/**
|
||||
* Read bean definitions from the given DOM document and
|
||||
* register them with the registry in the given reader context.
|
||||
* @param doc the DOM document
|
||||
* @param readerContext the current context of the reader. Includes the resource being parsed
|
||||
* @param readerContext the current context of the reader
|
||||
* (includes the target registry and the resource being parsed)
|
||||
* @throws BeanDefinitionStoreException in case of parsing errors
|
||||
*/
|
||||
void registerBeanDefinitions(Document doc, XmlReaderContext readerContext)
|
||||
throws BeanDefinitionStoreException;
|
||||
|
||||
/**
|
||||
* Set the Environment to use when reading bean definitions. Used for evaluating
|
||||
* profile information to determine whether a {@code <beans/>} document/element should
|
||||
* be included or omitted.
|
||||
*/
|
||||
void setEnvironment(Environment environment);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -72,16 +72,15 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||
|
||||
public static final String RESOURCE_ATTRIBUTE = "resource";
|
||||
|
||||
/** @see org.springframework.context.annotation.Profile */
|
||||
public static final String PROFILE_ATTRIBUTE = "profile";
|
||||
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private XmlReaderContext readerContext;
|
||||
|
||||
private Environment environment;
|
||||
|
||||
private XmlReaderContext readerContext;
|
||||
|
||||
private BeanDefinitionParserDelegate delegate;
|
||||
|
||||
|
||||
@@ -104,13 +103,12 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||
*/
|
||||
public void registerBeanDefinitions(Document doc, XmlReaderContext readerContext) {
|
||||
this.readerContext = readerContext;
|
||||
|
||||
logger.debug("Loading bean definitions");
|
||||
Element root = doc.getDocumentElement();
|
||||
|
||||
doRegisterBeanDefinitions(root);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register each bean definition within the given root {@code <beans/>} element.
|
||||
* @throws IllegalStateException if {@code <beans profile="..."} attribute is present
|
||||
@@ -120,21 +118,22 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||
protected void doRegisterBeanDefinitions(Element root) {
|
||||
String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE);
|
||||
if (StringUtils.hasText(profileSpec)) {
|
||||
Assert.state(this.environment != null, "environment property must not be null");
|
||||
String[] specifiedProfiles = StringUtils.tokenizeToStringArray(profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
|
||||
Assert.state(this.environment != null, "Environment must be set for evaluating profiles");
|
||||
String[] specifiedProfiles = StringUtils.tokenizeToStringArray(
|
||||
profileSpec, BeanDefinitionParserDelegate.MULTI_VALUE_ATTRIBUTE_DELIMITERS);
|
||||
if (!this.environment.acceptsProfiles(specifiedProfiles)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// any nested <beans> elements will cause recursion in this method. In
|
||||
// Any nested <beans> elements will cause recursion in this method. In
|
||||
// order to propagate and preserve <beans> default-* attributes correctly,
|
||||
// keep track of the current (parent) delegate, which may be null. Create
|
||||
// the new (child) delegate with a reference to the parent for fallback purposes,
|
||||
// then ultimately reset this.delegate back to its original (parent) reference.
|
||||
// this behavior emulates a stack of delegates without actually necessitating one.
|
||||
BeanDefinitionParserDelegate parent = this.delegate;
|
||||
this.delegate = createHelper(readerContext, root, parent);
|
||||
this.delegate = createHelper(this.readerContext, root, parent);
|
||||
|
||||
preProcessXml(root);
|
||||
parseBeanDefinitions(root, this.delegate);
|
||||
@@ -143,7 +142,9 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume
|
||||
this.delegate = parent;
|
||||
}
|
||||
|
||||
protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
|
||||
protected BeanDefinitionParserDelegate createHelper(
|
||||
XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) {
|
||||
|
||||
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext, environment);
|
||||
delegate.initDefaults(root, parentDelegate);
|
||||
return delegate;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class DelegatingEntityResolver implements EntityResolver {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityResolver delegating " + XSD_SUFFIX + " to " + this.schemaResolver +
|
||||
" and " + DTD_SUFFIX + " to " + this.dtdResolver;
|
||||
" and " + DTD_SUFFIX + " to " + this.dtdResolver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -148,4 +148,4 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user