Skip to content

Call runners after ApplicationReadyEvent has been published #7656

@rupert-madden-abbott

Description

@rupert-madden-abbott

Spring Boot provides the very useful ApplicationRunner and CommandLineRunner for executing code immediately before the SpringApplication.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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions