-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Call runners after ApplicationReadyEvent has been published #7656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for raising this. I think that they should probably happen after the |
@wilkinsona this one has a side effect on a web application. If you use to run something in an This is easy to run in problem with devtools and LiveReload as the browser might refresh "too fast" and your app is in an inconsistent state then. I think we need to make sure to update the release notes to:
|
IMO, an application runner shouldn't be used for initialisation. If you need to initialise something it should be done as part of application context refresh. If you need that initialisation to happen after something, then the standard dependency mechanisms offered by the Framework should be used. I'm struggling to think of a use case where a component's dependency would effectively be everything. |
+1 on documenting that CommandLineRunner and ApplicationRunner should only be used for initialization work and nothing more. |
@frederikvanhoyweghen this issue is closed so please do not comment here to suggest a change. Your use case is also quite specific to Spring Boot Admin so I'd rather ask there but if you have some ideas to generically improve the documentation, please create a separate issue. |
Sorry, I didn't notice the issue was closed. I took it up with the spring boot admin maintainers, I'll create a separate issue if need be. Thanks! |
Spring Boot provides the very useful
ApplicationRunner
andCommandLineRunner
for executing code immediately before theSpringApplication.run
method finishes.There are many articles and StackOverflow questions (example 1, example 2) that advocate using these for the bulk of the logic within a Command Line application.
However, if you use one of these, then the "Started ApplicationName in X seconds" log message is output after the runners have finished. Additionally, the event
ApplicationReadyEvent
is called afterwards as well.This implies that runners are only intended for initialisation work. You should not, in fact, be using them for work that should be considered part of running the application and doing so is a misuse of their intended purpose.
Can we please have some clarity on the proper usage added to the documentation if this is indeed a misuse?
If it is not a misuse then can the runner execution get moved to after the
ApplicationReadyEvent
, and after the "Started" log message, to more clearly indicate that the application is already, in fact, ready, and now the runner execution is part of the application itself running?The text was updated successfully, but these errors were encountered: