From d2188a36ffbb40643baa12f9a68494774552563f Mon Sep 17 00:00:00 2001 From: Emmanuel Bourg Date: Tue, 1 Jan 2019 11:22:29 +0100 Subject: New upstream version 4.3.21 --- .../org/springframework/beans/ExtendedBeanInfo.java | 6 +++++- .../beans/factory/ListableBeanFactory.java | 10 +++++++--- .../annotation/AnnotationBeanWiringInfoResolver.java | 19 +++++++++---------- .../beans/factory/support/AbstractBeanFactory.java | 16 +++++++++++++--- .../factory/support/DefaultListableBeanFactory.java | 4 +++- 5 files changed, 37 insertions(+), 18 deletions(-) (limited to 'spring-beans/src/main/java/org') diff --git a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java index 1411f556..5c0942cf 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -43,8 +43,10 @@ import org.springframework.util.ObjectUtils; * Decorator for a standard {@link BeanInfo} object, e.g. as created by * {@link Introspector#getBeanInfo(Class)}, designed to discover and register static * and/or non-void returning setter methods. For example: + * *
  * public class Bean {
+ *
  *     private Foo foo;
  *
  *     public Foo getFoo() {
@@ -56,6 +58,7 @@ import org.springframework.util.ObjectUtils;
  *         return this;
  *     }
  * }
+ * * 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. @@ -68,6 +71,7 @@ import org.springframework.util.ObjectUtils; * indexed properties are fully supported. * * @author Chris Beams + * @author Juergen Hoeller * @since 3.1 * @see #ExtendedBeanInfo(BeanInfo) * @see ExtendedBeanInfoFactory diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java index e8be3322..1c0c70b4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/ListableBeanFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -243,7 +243,9 @@ public interface ListableBeanFactory extends BeanFactory { /** * Find all names of beans whose {@code Class} has the supplied {@link Annotation} - * type, without creating any bean instances yet. + * type, without creating corresponding bean instances yet. + *

Note that this method considers objects created by FactoryBeans, which means + * that FactoryBeans will get initialized in order to determine their object type. * @param annotationType the type of annotation to look for * @return the names of all matching beans * @since 4.0 @@ -253,6 +255,8 @@ public interface ListableBeanFactory extends BeanFactory { /** * Find all beans whose {@code Class} has the supplied {@link Annotation} type, * returning a Map of bean names with corresponding bean instances. + *

Note that this method considers objects created by FactoryBeans, which means + * that FactoryBeans will get initialized in order to determine their object type. * @param annotationType the type of annotation to look for * @return a Map with the matching beans, containing the bean names as * keys and the corresponding bean instances as values @@ -267,7 +271,7 @@ public interface ListableBeanFactory extends BeanFactory { * found on the given class itself. * @param beanName the name of the bean to look for annotations on * @param annotationType the annotation class to look for - * @return the annotation of the given type if found, or {@code null} + * @return the annotation of the given type if found, or {@code null} otherwise * @throws NoSuchBeanDefinitionException if there is no bean with the given name * @since 3.0 */ diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java index 78fe8fe8..e8e20ab0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 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. @@ -44,24 +44,23 @@ public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver } /** - * Build the BeanWiringInfo for the given Configurable annotation. + * Build the {@link BeanWiringInfo} for the given {@link Configurable} annotation. * @param beanInstance the bean instance * @param annotation the Configurable annotation found on the bean class * @return the resolved BeanWiringInfo */ protected BeanWiringInfo buildWiringInfo(Object beanInstance, Configurable annotation) { if (!Autowire.NO.equals(annotation.autowire())) { + // Autowiring by name or by type return new BeanWiringInfo(annotation.autowire().value(), annotation.dependencyCheck()); } + else if (!"".equals(annotation.value())) { + // Explicitly specified bean name for bean definition to take property values from + return new BeanWiringInfo(annotation.value(), false); + } else { - if (!"".equals(annotation.value())) { - // explicitly specified bean name - return new BeanWiringInfo(annotation.value(), false); - } - else { - // default bean name - return new BeanWiringInfo(getDefaultBeanName(beanInstance), true); - } + // Default bean name for bean definition to take property values from + return new BeanWiringInfo(getDefaultBeanName(beanInstance), true); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index 734aef5a..1e021cc9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java @@ -509,12 +509,21 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp // Generics potentially only match on the target class, not on the proxy... RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName); Class targetType = mbd.getTargetType(); - if (targetType != null && targetType != ClassUtils.getUserClass(beanInstance) && - typeToMatch.isAssignableFrom(targetType)) { + if (targetType != null && targetType != ClassUtils.getUserClass(beanInstance)) { // Check raw class match as well, making sure it's exposed on the proxy. Class classToMatch = typeToMatch.resolve(); - return (classToMatch == null || classToMatch.isInstance(beanInstance)); + if (classToMatch != null && !classToMatch.isInstance(beanInstance)) { + return false; + } + if (typeToMatch.isAssignableFrom(targetType)) { + return true; + } } + ResolvableType resolvableType = mbd.targetType; + if (resolvableType == null) { + resolvableType = mbd.factoryMethodReturnType; + } + return (resolvableType != null && typeToMatch.isAssignableFrom(resolvableType)); } } return false; @@ -1363,6 +1372,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp */ protected Class resolveBeanClass(final RootBeanDefinition mbd, String beanName, final Class... typesToMatch) throws CannotLoadBeanClassException { + try { if (mbd.hasBeanClass()) { return mbd.getBeanClass(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index c3ea84a0..bb5ff2cf 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -1574,7 +1574,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } // Lenient fallback: dummy factory in case of original factory not found... - return new DefaultListableBeanFactory(); + DefaultListableBeanFactory dummyFactory = new DefaultListableBeanFactory(); + dummyFactory.serializationId = this.id; + return dummyFactory; } } -- cgit v1.2.3