Skip to content
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

Update documentation to reflect the web server now being started immediately before the ContextRefreshedEvent is published #22277

Closed
ykalemi opened this issue Jul 9, 2020 · 3 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@ykalemi
Copy link

ykalemi commented Jul 9, 2020

There are some behavior changes in Spring Boot 2.3.0. This issue #21325 commit introduced new Web Server lifecycle logic - WebServerStartStopLifecycle. And now there is this order during an applicaton startup:

  1. WebServerStartStopLifecycle.start -> webServer.start
  2. publishEvent(new ContextRefreshedEvent(this));

In Spring Boot 2.2.0 there was another logic (ServletWebServerApplicationContext.java):

protected void finishRefresh() {
    super.finishRefresh();
    WebServer webServer = startWebServer();
    if (webServer != null) {
        publishEvent(new ServletWebServerInitializedEvent(webServer, this));
    }
}

And order was like this:

  1. publishEvent(new ContextRefreshedEvent(this));
  2. webServer.start

We run some logic after the Spring context has been initialized but before web server started. With Spring Boot 2.3.0 web server processes requests before this logic is done.

If it is an expected change of events order, it should be mentioned in migration guide.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 9, 2020
@wilkinsona
Copy link
Member

It is expected, but it looks like we have a bit of tidying up to do after that change, both in the migration guide and in a few places in the code. Thanks for letting us know.

@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 9, 2020
@wilkinsona wilkinsona changed the title 2.3.0 behavior change: Web server starts now before ContextRefreshedEvent Update documentation to reflect the web server now being started immediately before the ContextRefreshedEvent is published Jul 9, 2020
@wilkinsona wilkinsona added this to the 2.3.x milestone Jul 9, 2020
@ykalemi
Copy link
Author

ykalemi commented Jul 9, 2020

@wilkinsona thanks for your answer.
Is there another possibility to run some code after context has been initialized but before web server started? Should there be some other extension point for this?

@wilkinsona
Copy link
Member

Generally, we expect that sort of work to be done as part of the usual bean lifecycle. There are lots of different options depending on exactly what you want to do. For example, the code could be run:

  • as part of a bean's construction
  • in a @PostConstruct method
  • in afterPropertiesSet() having implemented InitializingBean
  • in start() having implemented Lifecycle or SmartLifecycle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants