Skip to content

Commit 1b4e02b

Browse files
committed
RequiredAnnotationBeanPostProcessor skips factory-bean definitions
Also moving the associated unit tests to the correct package beans.factory.annotation Issue: SPR-10458
1 parent 161819f commit 1b4e02b

File tree

4 files changed

+271
-197
lines changed

4 files changed

+271
-197
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.beans.factory.BeanFactory;
3131
import org.springframework.beans.factory.BeanFactoryAware;
3232
import org.springframework.beans.factory.BeanInitializationException;
33+
import org.springframework.beans.factory.config.BeanDefinition;
3334
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3435
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
3536
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
@@ -165,6 +166,8 @@ public PropertyValues postProcessPropertyValues(
165166
* required property check as performed by this post-processor.
166167
* <p>The default implementations check for the presence of the
167168
* {@link #SKIP_REQUIRED_CHECK_ATTRIBUTE} attribute in the bean definition, if any.
169+
* It also suggests skipping in case of a bean definition with a "factory-bean"
170+
* reference set, assuming that instance-based factories pre-populate the bean.
168171
* @param beanFactory the BeanFactory to check against
169172
* @param beanName the name of the bean to check against
170173
* @return {@code true} to skip the bean; {@code false} to process it
@@ -173,7 +176,11 @@ protected boolean shouldSkip(ConfigurableListableBeanFactory beanFactory, String
173176
if (beanFactory == null || !beanFactory.containsBeanDefinition(beanName)) {
174177
return false;
175178
}
176-
Object value = beanFactory.getBeanDefinition(beanName).getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
179+
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
180+
if (beanDefinition.getFactoryBeanName() != null) {
181+
return true;
182+
}
183+
Object value = beanDefinition.getAttribute(SKIP_REQUIRED_CHECK_ATTRIBUTE);
177184
return (value != null && (Boolean.TRUE.equals(value) || Boolean.valueOf(value.toString())));
178185
}
179186

spring-beans/src/test/java/org/springframework/beans/annotation/RequiredAnnotationBeanPostProcessorTests.java

-195
This file was deleted.

spring-beans/src/test/java/org/springframework/beans/annotation/AnnotationBeanWiringInfoResolverTests.java renamed to spring-beans/src/test/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolverTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.beans.annotation;
17+
package org.springframework.beans.factory.annotation;
1818

1919
import static org.junit.Assert.*;
2020

0 commit comments

Comments
 (0)