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
Allow @WebListener ServletContextListeners to programmatically add servlets and filters #18303
Comments
Thanks, @janbartel. This is a known limitation at the moment due to the way that Spring Boot scans for and registers |
@wilkinsona the way our own handling of ListenerHolder h = _context.getServletHandler().newListenerHolder(new Source(Source.Origin.ANNOTATION, clazz.getName()));
h.setHeldClass(clazz);
_context.getServletHandler().addListener(h); Where |
For JoinFaces we've implemented a @wilkinsona Could the implementation behind |
I have a proposal for this but there is a small chance that it will be a breaking change. As such, I'm wonder if it may be a little too risky to do it in 2.2.x. |
The proposal requires some further thought as there are some package tangles at the moment. |
I've reworked the changes to remove the package tangles: https://github.com/wilkinsona/spring-boot/tree/gh-18303. |
- Spring issues related to spring-projects/spring-boot#18303
- Spring issues related to spring-projects/spring-boot#18303
SpringBoot version 2.1.8.RELEASE
Please refer to jetty issue jetty/jetty.project#4103.
See also StackOverflow reports of same problem for Tomcat: https://stackoverflow.com/questions/44389716/spring-boot-embedded-tomcat-weblistener-scanned-by-servletcomponentscan
The issue is that a ServletContextListener that is annotated with
@WebListener
is not able to programmatically add Servlets (and I suppose Filters, but I didn't test that), but throws an UnsupportedOperationException. Here's an example of such an exception for jetty:This problem occurs because springboot is processing the
@WebListener
annotation and then using the ServletContext programmatic interfaces to add the listener: this classifies the listener as being programmatically added, and thus not permitted to add servlets/filters/listeners in itscontextInitialized()
method. See the ServletSpecification section 4.4:Here is the springboot stacktrace showing where the
@WebListener
is being added as a programmatic listener:The text was updated successfully, but these errors were encountered: