We have 4 Beans BeanA, BeanB, BeanC, BeanD We have a cache in BeanA which gets filled in the @PostConstruct of BeanA. Now, BeanB also have a cache which gets filled in the @PostConstruct of BeanB.
BeanB's cache depends on the BeanA's cache. So BeanB should be created only after successfully creation of BeanA and BeanA's cache.
Can we ensure this using @DependsOn? What role does @PostContruct performs? When we say BeanA is succesfully created do we mean it's @PostConstruct has been completed successfully?
If not @DependsOn is there any other way to ensure this.
public class BeanA {
private ConcurrentCache<> cacheA;
@PostConstruct
void init() {
cache = fillingCache();
}
}
public class BeanB {
private ConcurrentCache<> cacheB;
@Autowired
private BeanA beanA;
@PostConstruct
void init() {
cacheB = beanA.cacheA;
}
}