Skip to content

Commit e23ac03

Browse files
committed
Avoid stack overflow in case of chained factory-bean references to FactoryBean class
Issue: SPR-14551 (cherry picked from commit 8b5d355)
1 parent 79a5696 commit e23ac03

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -325,8 +325,8 @@ public Object configureBean(Object existingBean, String beanName) throws BeansEx
325325
}
326326

327327
@Override
328-
public Object resolveDependency(DependencyDescriptor descriptor, String beanName) throws BeansException {
329-
return resolveDependency(descriptor, beanName, null, null);
328+
public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException {
329+
return resolveDependency(descriptor, requestingBeanName, null, null);
330330
}
331331

332332

@@ -802,10 +802,14 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
802802
if (objectType.value != null) {
803803
return objectType.value;
804804
}
805+
else {
806+
// No type found for shortcut FactoryBean instance:
807+
// fall back to full creation of the FactoryBean instance.
808+
return super.getTypeForFactoryBean(beanName, mbd);
809+
}
805810
}
806811

807-
// No type found - fall back to full creation of the FactoryBean instance.
808-
return super.getTypeForFactoryBean(beanName, mbd);
812+
return null;
809813
}
810814

811815
/**
@@ -824,7 +828,7 @@ protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd,
824828
SmartInstantiationAwareBeanPostProcessor ibp = (SmartInstantiationAwareBeanPostProcessor) bp;
825829
exposedObject = ibp.getEarlyBeanReference(exposedObject, beanName);
826830
if (exposedObject == null) {
827-
return exposedObject;
831+
return null;
828832
}
829833
}
830834
}

spring-orm/src/test/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -90,7 +90,7 @@ protected int countRowsInTable(EntityManager em, String tableName) {
9090
}
9191

9292

93-
static enum Provider {
93+
enum Provider {
9494

9595
ECLIPSELINK, HIBERNATE, OPENJPA
9696
}

spring-orm/src/test/resources/org/springframework/orm/jpa/hibernate/hibernate-manager.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@
3030
</property>
3131
</bean>
3232

33+
<bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/>
34+
35+
<bean id="hibernateStatistics" factory-bean="sessionFactory" factory-method="getStatistics"/>
36+
37+
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
38+
3339
</beans>

0 commit comments

Comments
 (0)