- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug
Milestone
Description
Francisco Lozano opened SPR-16250 and commented
When a FactoryBean declaration returns null:
if (something != null) {
     MethodInvokingFactoryBean methodInvokingFactoryBean = new MethodInvokingFactoryBean();
     methodInvokingFactoryBean.setTargetClass(MyClass.class);
     methodInvokingFactoryBean.setTargetMethod("init");
     methodInvokingFactoryBean.setArguments(new Object[] { something });
     return methodInvokingFactoryBean;
} else {
     return null;
}
this happens:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodInvokingFactoryBean': Bean instance of type [class org.springframework.beans.factory.support.NullBean] is not a FactoryBean
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getFactoryBean(FactoryBeanRegistrySupport.java:208)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:955)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:833)
	at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:557)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:428)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:399)
	at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:222)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1273)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1098)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583)
	... 65 more
I guess it's the same as #20582, as the NullBean is being exposed.
Affects: 5.0.2
Reference URL: #20582
Issue Links:
- CastClass exception when wiring Map of beans (NullBean instead of 'null' in the map) [SPR-16033] #20582 CastClass exception when wiring Map of beans (NullBean instead of 'null' in the map)
- Autowire contract is not honored in cases where FactoryBean or @Bean return null [SPR-15829] #20384 Autowire contract is not honored in cases where FactoryBean or @Beanreturn null
Referenced from: commits 18d90ec
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)type: bugA general bugA general bug