-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Andreas Thaler opened SPR-10663 and commented
Assumed you have a BeanFactory designed for extension (for example using lookup-method)
public abstract class MyFactory implements FactoryBean{ ... }
configured as abstract bean
<bean id="myFactory" abstract="true" class="MyFactory">
then a call to ```
ApplicationContext.getBeansWithAnnotation(..)
As the class is an abstract class the call will fail with:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFactory' defined in class path resource [myConfig.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [MyFactory]: Is it an abstract class?; nested exception is java.lang.InstantiationException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:767)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:698)
at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:578)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAnnotationOnBean(DefaultListableBeanFactory.java:464)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansWithAnnotation(DefaultListableBeanFactory.java:449)
at org.springframework.context.support.AbstractApplicationContext.getBeansWithAnnotation(AbstractApplicationContext.java:1182)
at
...
Same scenario will work fine if class is not implementing FactoryBean, so it seems that for the special case of a FactoryBean the abstract flag is not repected.
Affects: 3.1.3
Sub-tasks:
- Backport "BeanFactory.getBeansWithAnnotation() should not consider abstract beans" [SPR-10672] #15300 Backport "BeanFactory.getBeansWithAnnotation() should not consider abstract beans"