Explicitly notify when a bean initialized using factory bean paradigm also implements FactoryBean [SPR-9981] #14615
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: invalid
An issue that we don't feel is valid
Mukarram Baig opened SPR-9981 and commented
When upgrading from 3.1.0 to 3.1.1, we noticed that a few factory bean definitions using the static method paradigm started to fail with a org.springframework.beans.factory.BeanIsNotAFactoryException: Bean named 'fooFactoryBean' must be of type [org.springframework.beans.factory.FactoryBean], but was actually of type [com.kilo.SpecialObject]. On further inspection, it turned out that the class itself was also implementing FactoryBean and hence the container was getting confused. Leveraging on the FactoryBean approach alone or not implementing the FactoryBean interface alone also solved the problems and it made sense, since I cannot think of a reason why someone may want two ways of getting a bean from it. However, since it used to work fine (by fine I mean without throwing any errors) upto 3.1.0, maybe it is a good idea to detect such a bean definition and flag it explicitly so that the clients can fix their code easily. Attaching a sample maven project where we can see the error in action. I searched through the release notes of 3.1.1 where I could find the changed behavior.
Thanks in advance!
Affects: 3.1.1
Reference URL: http://stackoverflow.com/questions/13309921/spring-factorybean-error-in-spring-3-1-1-but-not-in-3-1-0
Attachments:
The text was updated successfully, but these errors were encountered: