Closed
Description
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:
- JavaConfigBug.zip (7.50 kB)
Issue Links:
- Plain FactoryBean declaration on @Bean method leads to early call (pre injection) [SPR-12141] #16755 Plain FactoryBean declaration on
@Bean
method leads to early call (pre injection)
2 votes, 6 watchers