Reputation: 2239
I am reading the source code of Spring Boot and I found that Spring Boot refreshes the context right after preparing the context in the run method.
SpringApplication.run method:
...
prepareContext(context, environment, listeners, applicationArguments,printedBanner);
refreshContext(context);
...
Can anyone explain why refreshing context is needed? Thanks.
Upvotes: 3
Views: 1926
Reputation: 28106
Because refreshContext
causes context initialization/reinitialization, such as invoking BeanFactoryPostProcessor
beans, registering listeners, initilizing message source etc. You can see it in sources of the AbstractApplicationContext#refresh
method.
Here you can find an article about Spring internals and refresh process.
Upvotes: 2