Reputation:
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
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