Skip to content

NoUniqueBeanDefinitionException when autowiring static nested class that extends its containing class [SPR-12195] #16809

@spring-projects-issues

Description

@spring-projects-issues

Martin Kühl opened SPR-12195 and commented

Trying to autowire the component from code like the following
{code:}
class NestedBeans {
@Component
static class StaticNested extends NestedBeans {}
}


results in a NoUniqueBeanDefinitionException:
{code:}
NoUniqueBeanDefinitionException: No qualifying bean of type [com.example.NestedBeans$StaticNested] is defined: expected single matching bean but found 2: nestedBeans.StaticNested,com.example.NestedBeans$StaticNested

We can work around this by explicitly naming the component (see branch "named" in the reproduction repo). It also disappears when the nested class does not extend the containing class.


Affects: 3.1.4, 4.0.7

Reference URL: https://github.com/ewerk/bug-report_spring-static-nested-beans

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions