-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Refactor SpringBootServletInitializer.onStartup to initialize WebApplicationContext inside ServletContextListener #2070
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
@dsyer any thoughts? |
Looks harmless. (Famous last words.) |
I have to be a devil's advocate on this. The only drawback that I can think of, is that if anybody had implemented I don't know if anybody in the wild has any dependency on this behavior. On the pro side, I think the proposed change is more in-line with the Servlet framework, as it does extra initialization through a well defined hook, and allows other cooperative players to rely on a defined call order. -Alex |
I think we'll risk the change. |
|
OK, I've needed to revert that because we can't add Servlets from the |
@apogrebnyak Can you provide a bit more detail about the underlying reason that you wanted this change. Perhaps there is some other way that we can fix it? |
I've reviewed your checking and now I see why I did not hit this exception earlier. In the original proposal, the listener is created through anonymous class, and the In the 1763148 a stand-alone listener class is created and the context passed in the event is used. After debugging Tomcat initialization code I see that the two Now back to my reason for requesting this bug. I had a legacy ServletContextListener, that I wanted to initialize before the SpringBoot application. I think, in view of how fragile So, please revert to original |
Great thanks. If you can provide a sample project with the new issue that you open that will be very helpful. |
Created request for |
Currently, onStartup creates a web application, and only then registers a ServletContextListener (to react to contextDestroyed event).
If an application wants to register some other ServletContextListener before the SpringApplication is created it cannot reuse current onStartup method. I propose that onStartup be refactored to register a fully functioning ServletContextListener, that will be called by the Servlet container.
Here is a proposed refactoring:
With this change client application would be able to do the following:
and ensure that listeners are called in order. Currently all listeners will be called only after SpringApplication has already been initialized (For some legacy applications this may not be desirable).
The text was updated successfully, but these errors were encountered: