Skip to content

Provide alternatives to using FactoryBean types within @Bean methods [SPR-7418] #12076

Closed

Description

@spring-projects-issues

Chris Beams opened SPR-7418 and commented

Consolidating the following issues related to using FactoryBean implementations within @Bean methods:


Affects: 3.0 GA

Sub-tasks:

Issue Links:

4 votes, 4 watchers

Activity

  1. spring-projects-issues commented on Mar 10, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    After consideration, the goal is not to provide support for using FactoryBean instances within @Bean methods, but rather to eliminate the need to do so altogether.

    It is fundamentally awkward to use a FactoryBean in a @Configuration class context; they were designed specifically as a mechanism to work around limitations of XML-based configuration. Rather, what's needed is a more fundamental, possibly builder-style API instead of a FactoryBean API. In many cases, today's current FactoryBeans may be refactored to delegate to simpler builder-style APIs that can be used in a @Bean method as well.

    In other cases, it may be sufficient to simply use an existing native API such as Hibernate's Configuration class.

    Or it may be beneficial to provide a Spring-specific subclass of a native API in order to ensure certain container lifecycle hooks are invoked, etc. (e.g. a Hibernate Configuration subclass that implements Spring's DisposableBean).

    This is a high-priority issue for Spring 3.1 M2, as 100% convenient code-based configuration cannot be fully realized without addressing it.

  2. spring-projects-issues commented on Dec 6, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    Users should not, in most cases need to use FactoryBean types within @Bean methods. There are certain exceptions, such as LocalEntityManagerFactoryBean, and for reasons documented in #12779. There are other exceptions, but we will consider implementing alternatives for them on a case-by-case basis going forward, based on user demand.

  3. added
    type: enhancement
    in: core
    on Jan 11, 2019
  4. added this to the 3.1 GA 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

No one assigned

    Labels

    in: coretype: enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions