You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression in 4.1: UnsatisfiedDependencyException because a prototype-scoped FactoryBean is unexpectedly instantiated by getTypeForFactoryBean() [SPR-12786] #17383
This turns out to be a regression caused by #16461, where the algorithm doesn't stop at a declared FactoryBean<Object> (such as a plain JndiObjectFactoryBean) for @Bean methods anymore but rather tries to partially instantiate the target bean in such a case. I've addressed this through a catch block within getNonSingletonFactoryBeanForTypeCheck, ignoring a non-singleton candidate bean if we fail to instantiate it.
Note that I strongly recommend avoiding such declarations. A non-singleton FactoryBean is rather odd in general, but for any scope: Prefer a direct DataSource return type or whatever you retrieve from JNDI instead, using a JndiLocatorDelegate instead of a JndiObjectFactoryBean. If you insist on a FactoryBean, preferably declare a FactoryBean<DataSource> return type on your @Bean method instead of a plain FactoryBean implementation class.
Activity
spring-projects-issues commentedon Mar 5, 2015
Juergen Hoeller commented
This turns out to be a regression caused by #16461, where the algorithm doesn't stop at a declared
FactoryBean<Object>(such as a plainJndiObjectFactoryBean) for@Beanmethods anymore but rather tries to partially instantiate the target bean in such a case. I've addressed this through a catch block withingetNonSingletonFactoryBeanForTypeCheck, ignoring a non-singleton candidate bean if we fail to instantiate it.Note that I strongly recommend avoiding such declarations. A non-singleton
FactoryBeanis rather odd in general, but for any scope: Prefer a directDataSourcereturn type or whatever you retrieve from JNDI instead, using aJndiLocatorDelegateinstead of aJndiObjectFactoryBean. If you insist on aFactoryBean, preferably declare aFactoryBean<DataSource>return type on your@Beanmethod instead of a plainFactoryBeanimplementation class.Juergen