本文介绍了抓住春天初始化所有豆子的时刻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有spring应用程序(我没有懒豆)。
I have spring application(I haven't lazy beans).
我想在所有@Component(@Repositoey @Service @Controller)时插入逻辑bean被初始化。
I want to insert logic to place when all @Component(@Repositoey @Service @Controller) beans are initialized.
我该怎么做?
推荐答案
正如的答案中所述,您可以使用ApplicationListener并查找:
As mentioned in the answer to this question, you could use ApplicationListener and look for the ContextRefreshedEvent:
public class Loader implements ApplicationListener<ContextRefreshedEvent>{
public void onApplicationEvent(ContextRefreshedEvent event) {
// whatever you want to do when app context is initialized or refreshed
}
}
这篇关于抓住春天初始化所有豆子的时刻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!