spring-boot: Embedded Tomcat does not honor ServletContainerInitializers

Currently, the embedded Tomcat container does not detect and execute ServletContainerInitializers. This means that dependencies that use them are never called and therefore are unable to contribute to the running application.

The embedded Tomcat container should be enhanced such that it properly notices the ServletContainerInitializers on the Application’s classpath and executes them.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 22 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@philwebb could you be a bit more explicit what lead you to this design decision? What’s problematic about the search algorithm? Where in the boot source code do you disable that feature? Why wouldn’t you want the ServletContainerInitializer to be executed when you run java -jar? Would you consider supporting ServletContainerInitializer if some of the issues with it could be resolved?

Also it’s not magical to execute all ServletContainerInitializers. java.util.ServiceLoader.load(javax.servlet.ServletContainerInitializer) should do the trick as all implementations of that interface have to be listed in /META-INF/services/javax.servlet.ServletContainerInitializer.

Servlet 3.0 made a really good job at defining this interface and the @Web* annotations as it makes it possible to write modular extensions to web applications (like stagemonitor) that just have to be on the classpath to be active and that are completely technology agnostic. It’s really a pity that boot beaks the spec multiple times (neither ServletContainerInitializer nor @Web* annotations are supported) which makes these mechanisms useless because they don’t work with boot, which is a (btw great) technology that just can’t be ignored.

The goal of these servlet 3.0 mechanisms is to enable integration of standardized components without the user having to explicitly configure something. It’s sad that boot makes that impossible 😦