Class User
{
@Autowired
private MyOtherBean;
@PostConstruct
public void init(){
for(MyObject value : myOtherBean.getValues()){
}
}
}
Class MyOtherBean
{
@Autowired
private MyOtherBean1;
@PostConstruct
public void init(){
MyOtherBean1.populateValues();
}
public Collection<MyObject> getValues(){
}
}
Issue : Intermittent
Description : Now in my case, PostCostruct for User is getting called first. MyOtherBean PostConstruct is called after that which actually populate values.
When User PostConstruct tries getValues it returns null and results into NPE.
Questions
- Any way to avoid this ?
- What is the correct standard way to avoid such dependency?