java listen to ContextRefreshedEvent

后端 未结 3 876
我寻月下人不归
我寻月下人不归 2021-02-04 09:30

I have a classX in my spring application in which I want to be able to find out if all spring beans have been initialized. To do this, I am trying to listen ContextRefreshedEven

3条回答
  •  情话喂你
    2021-02-04 10:16

    Spring >= 4.2

    You can use annotation-driven event listener as below :

    @Component
    public class classX  {
    
        @EventListener
        public void handleContextRefresh(ContextRefreshedEvent event) {
    
        }
    }
    

    the ApplicationListener you want to register is defined in the signature of the method.

提交回复
热议问题