I have a problem and this is the gist of it: (there are more classes involved in the loop but it can be represented this way)
@service
public class serviceDispatcher{
@Autowired
private BeanA a;
@Autowired
private BeanB b;
public BeanA getBeanA(){
return a;
}
public BeanB getBeanB(){
return b;
}
}
@Service
public class BeanA{
@Autowired
ServiceDispatcher sd;
@PostConstruct
private void init(){
sd.getBeanB().method;
}
}
so obviously I get a null pointer since BeanB b is not yet resolved. I also used afterPropertiesSet and it is the same. My question is that if there is a way to run the init() method after the whole context is initialized so that I don't get this null pointer? I am aware of the fact that having this circular dependency is trouble and needs to be solved but I'm just refactoring a huge project to use Spring DI and changing the design, logic and business requires a long process of asking it to be done by other teams.