Skip to content

Enhancement: @UniqueBean on interface or unique-beans: Class[] in application.yml #35972

@nealeu

Description

@nealeu

We like having interfaces define a contract for beans, and we also like having things like auto-configuration.

However, we can have situations where we know we only want there to ever be one implementation of an interface in the bean registry.

As a developer or perhaps even ops, I want to have duplicate bean definitions caught early instead of at the @Autowired site.

Would it work to either have something like:

package com.acme;

@UniqueBean
interface MyBean {
}

or

application.yml

spring:
  unique-beans:
    - com.acme.MyBean

We could then get a different exception thrown for this scenario, and and a far simpler exception report than the NoUniqueBeanDefinitionException report which is often not the information that is best to diagnose the cause of the duplication.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions