我有 spring 应用程序(我没有懒 bean)。
我想在所有 @Component(@Repositoey @Service @Controller) bean 初始化时插入逻辑。
我该怎么做?
最佳答案
如 this question 的回答中所述,您可以使用 ApplicationListener 并查找 ContextRefreshedEvent :
public class Loader implements ApplicationListener<ContextRefreshedEvent>{
public void onApplicationEvent(ContextRefreshedEvent event) {
// whatever you want to do when app context is initialized or refreshed
}
}
关于java - 捕捉spring初始化所有bean的时刻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19541600/