Skip to content

Commit 56f8d17

Browse files
committed
FactoryBean type check logs currently-in-creation exception at debug level
Issue: SPR-12900 (cherry picked from commit 65ba72f)
1 parent 6783ba2 commit 56f8d17

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1422,9 +1422,15 @@ protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd
14221422
return getTypeForFactoryBean(factoryBean);
14231423
}
14241424
catch (BeanCreationException ex) {
1425-
// Can only happen when getting a FactoryBean.
1426-
if (logger.isWarnEnabled()) {
1427-
logger.warn("Bean creation exception on FactoryBean type check: " + ex);
1425+
if (ex instanceof BeanCurrentlyInCreationException) {
1426+
if (logger.isDebugEnabled()) {
1427+
logger.debug("Bean currently in creation on FactoryBean type check: " + ex);
1428+
}
1429+
}
1430+
else {
1431+
if (logger.isWarnEnabled()) {
1432+
logger.warn("Bean creation exception on FactoryBean type check: " + ex);
1433+
}
14281434
}
14291435
onSuppressedException(ex);
14301436
return null;

spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests-withAutowiring.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<bean id="gamma" class="org.springframework.beans.factory.FactoryBeanTests$Gamma"/>
1313

14-
<bean id="betaFactory" class="org.springframework.beans.factory.FactoryBeanTests$BetaFactoryBean">
14+
<bean id="betaFactory" class="org.springframework.beans.factory.FactoryBeanTests$BetaFactoryBean" autowire="constructor">
1515
<property name="beta" ref="beta"/>
1616
</bean>
1717

spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
2222

2323
import org.junit.Test;
2424

25-
import org.springframework.beans.BeansException;
2625
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
2726
import org.springframework.beans.factory.config.BeanPostProcessor;
2827
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -39,14 +38,15 @@
3938
* @author Juergen Hoeller
4039
* @author Chris Beams
4140
*/
42-
public final class FactoryBeanTests {
41+
public class FactoryBeanTests {
4342

4443
private static final Class<?> CLASS = FactoryBeanTests.class;
4544
private static final Resource RETURNS_NULL_CONTEXT = qualifiedResource(CLASS, "returnsNull.xml");
4645
private static final Resource WITH_AUTOWIRING_CONTEXT = qualifiedResource(CLASS, "withAutowiring.xml");
4746
private static final Resource ABSTRACT_CONTEXT = qualifiedResource(CLASS, "abstract.xml");
4847
private static final Resource CIRCULAR_CONTEXT = qualifiedResource(CLASS, "circular.xml");
4948

49+
5050
@Test
5151
public void testFactoryBeanReturnsNull() throws Exception {
5252
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
@@ -63,10 +63,13 @@ public void testFactoryBeansWithAutowiring() throws Exception {
6363
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
6464
ppc.postProcessBeanFactory(factory);
6565

66+
assertNull(factory.getType("betaFactory"));
67+
6668
Alpha alpha = (Alpha) factory.getBean("alpha");
6769
Beta beta = (Beta) factory.getBean("beta");
6870
Gamma gamma = (Gamma) factory.getBean("gamma");
6971
Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");
72+
7073
assertSame(beta, alpha.getBeta());
7174
assertSame(gamma, beta.getGamma());
7275
assertSame(gamma2, beta.getGamma());
@@ -194,6 +197,9 @@ public static class Gamma {
194197
@Component
195198
public static class BetaFactoryBean implements FactoryBean<Object> {
196199

200+
public BetaFactoryBean(Alpha alpha) {
201+
}
202+
197203
private Beta beta;
198204

199205
public void setBeta(Beta beta) {
@@ -238,12 +244,12 @@ public PassThroughFactoryBean(Class<T> type) {
238244
public void setInstanceName(String instanceName) {
239245
this.instanceName = instanceName;
240246
}
247+
241248
@Override
242-
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
249+
public void setBeanFactory(BeanFactory beanFactory) {
243250
this.beanFactory = beanFactory;
244251
}
245252

246-
247253
@Override
248254
public T getObject() {
249255
if (instance == null) {

0 commit comments

Comments
 (0)