项目场景:
多个类中 使用@PostConstruct加载先后顺序
问题描述
有时候Class A中@PostConstruct注解的方法中的代码执行,需要等待Class B中@PostConstruct 注解方法中的代码执行完后,拿到结果,才能执行,也就是中A中某些代码的执行需要依赖B中代码执后的结果,此时就需要B先执行完,再执行A,
解决方案:
可以在A中先注入B,那么就会先加载B
@Service@DependsOn("b")public class A{@PostConstructpublic void init() {}}
@Servicepublic class B{@PostConstructpublic void init() {}}