Skip to content

Regression in 4.1: UnsatisfiedDependencyException because a prototype-scoped FactoryBean is unexpectedly instantiated by getTypeForFactoryBean() [SPR-12786] #17383

Closed

Description

@spring-projects-issues

Reid Harrison opened SPR-12786 and commented

Occurs after update to 4.1.4 from 4.0.4. More specifically, 4.0.9 to 4.1.0.

Please see https://github.com/reid-harrison/my-failing-bean for a sample project that reproduces the issue.


Affects: 4.1 GA, 4.1.5

Reference URL: http://stackoverflow.com/questions/28859716/prototype-scoped-spring-bean-incorrectly-created-at-context-creation-time-after

Issue Links:

Referenced from: commits 9b25d6a, f01a030

Activity

  1. spring-projects-issues commented on Mar 5, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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 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.

    Juergen

  2. added
    type: bug
    in: test
    in: core
    on Jan 11, 2019
  3. added this to the 4.1.6 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corein: testtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions