Skip to content

null FactoryBean results in BeanCreationException [SPR-16250] #20797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Nov 30, 2017 · 0 comments
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 30, 2017

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:

Referenced from: commits 18d90ec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants