Given the following code:
public class MyService implements InitializingBean {
@Autowired
private Set<MyDep> allDeps;
@Override
public void afterPropertiesSet() {
... use 'allDeps' here ...
}
}
MyDep
is an interface with three different implementations all of which also implement InitializingBean
(by extending the same abstract base class).
When I go to use allDeps
during set up of MyService
only 2 out of the 3 injected instances are themselves fully initialized. One of the instances is constructed and injected, but it's afterPropertiesSet()
has not yet been run. In the other two instances it has been run.
It's been my understanding that Spring will run afterPropertiesSet()
on a bean only after all of its dependencies are injected, and they will only be injected once they're fully initialized. Perhaps my understanding is wrong? Is this a bug in Spring? I've also tried using getBeansOfType(MyDep.class)
with the same results.
FWIW, looks like there's an similar unanswered question from 2 years ago. So perhaps it's time to re-ask? Spring dependency injection not completing in time