Injecting one qualified bean disrupts the ability to inject another qualified bean by subtype #33399
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: waiting-for-triage
An issue we've not yet triaged or decided on
Affects: spring-framework 6.1.12
We are trying to manage a fleet of similarly-typed beans to inject. We've found a surprising circumstance where the existence of a dependency on one bean ("A") will cause another bean ("B") to vary how you may inject it.
Below please find a test case showing the problem. The test case is attempting to inject
@Named("B") IImpl<String> bStr
, a concrete subtype of an interfaceI<String>
. The subtype is desired to access test-stubbing features not present on the interface.A different component is declaring
@Named("A") I<UUID> aUuid
. These definitions seem unrelated, since both the name (A
vsB
) and type (I<String>
vsI<UUID>
) differ.The test fails as is:
@Named("B") IImpl<String>
to@Named("B") I<String>
works, but then you cannot access the subtype's features@Import(MyConfig.ConsumeA.class)
causes the injection of B to work, despite only changing the use ofA
notB
!This behavior seems very surprising to me, and feels like a bug.
Thank you for your thoughts.
The text was updated successfully, but these errors were encountered: