Skip to content

Better error reporting for circular dependencies between JavaConfig classes [SPR-12317] #16922

Closed
@spring-projects-issues

Description

@spring-projects-issues

Eberhard Wolff opened SPR-12317 and commented

In the attached project we have

  • Java Configuration class A. It uses a bean of type Z that is @Autowired. It provides a bean of type B.
  • Java Configuration class AStrich provides the bean of type Z and has a bean of type B @Autowired.
    So the two Java Configuration classes are in a cyclic dependency due to the Beans of type B and Z.
    When bean B in A is created Z is not injected - which IMHO is wrong. It should be possible to rely on Spring autowiring all fields before a bean is created. Note that the problem disappears if B is not injected in AStrich any more and no cyclic dependency is present.
    This might look like a corner case but at my client it caused some headaches during an XML->JavaConfig migration.
    The attached project can be run with mvn test and fails due to the bug.

Affects: 4.1.1

Attachments:

Issue Links:

2 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions