I need one component to initialize before another. With @DependsOn it will look something like this:
@Component("beana")
public class BeanA{
@PostConstruct
void init(){
}
}
@Component("beanb")
@DependsOn("beana")
public class BeanB{
@PostConstruct
void init(){
}
}
Now I have to tell BeanB that it depends on the initialization of BeanA. My problem is that I do not want BeanB to know about the existence of BeanAs (for example, when BeanB just publishes events in an EventBus, and BeanA initializes and processes these events). I would like to use annotation in BeanA, stating that it must be initialized before BeanB. So, it will be something like this:
@Component("beana")
@RequiredBy("beanb")
public class BeanA{
@PostConstruct
void init(){
}
}
@Component("beanb")
public class BeanB{
@PostConstruct
void init(){
}
}
Is there any annotation or the ability to handle it like this?
source
share