Skip to content

Bean definition DSL does not generate unique bean names [SPR-17242] #21775

Closed

Description

@spring-projects-issues

Brian Clozel opened SPR-17242 and commented

When using the bean definition DSL, using the simplest variant of the DSL for defining beans like this creates issues:

val beans = beans {
    bean { fooRouter() } // defines a RouterFunction
    bean { barRouter() } // defines a RouterFunction
}

If no bean name is provided by the bean registration DSL call, GenericApplicationContext.registerBean will register it by default with the bean class name, which means that it's easy to override another definition, and impossible to define multiple beans of the same type without manually defining bean names.

Could we add other strategies that fall back on default bean names, to be more in line with the annotation/XML models? Could we try and derive that information from other parts of the DSL?


Affects: 5.0.8

Reference URL: spring-projects/spring-boot#14295

Issue Links:

Referenced from: commits b6d32ef

Activity

  1. spring-projects-issues commented on Sep 7, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    +1 for generating unique bean names, I faced this issue multiple times in Kotlin functional web applications and Spring Fu.

  2. spring-projects-issues commented on Sep 12, 2018

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    We're calling BeanDefinitionReaderUtils.uniqueBeanName for turning the class name into a unique bean name now: through appending a counter as suffix, similar to XML bean definitions.

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

Labels

in: coretype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions