user2740224
user2740224

Reputation:

catch moment when spring initialized all beans

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?

Upvotes: 12

Views: 7181

Answers (1)

trf
trf

Reputation: 1394

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

Upvotes: 17

Related Questions