catch moment when spring initialized all beans

瘦欲@ 提交于 2019-12-06 20:47:39

问题


I have spring application(I haven't lazy beans).

I want to insert logic to place when all @Component(@Repositoey @Service @Controller) beans are initialized.

How can I make it?


回答1:


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
        }
}


来源:https://stackoverflow.com/questions/19541600/catch-moment-when-spring-initialized-all-beans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!