question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedded Tomcat does not honor ServletContainerInitializers

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
felixbarnycommented, May 31, 2015

@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 😦

0reactions
felixbarnycommented, Jun 9, 2015

The spring-boot-samples tests are passing. Deploying the spring-boot-sample-web-jsp war to tomcat did also work. But the tests in org.springframework.boot.autoconfigure.security.oauth2.SpringSecurityOAuth2AutoConfigurationTestsare failing with the following exception:

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:188)
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:917)
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
    ... 6 more
Caused by: java.lang.IllegalStateException: No SpringApplication sources have been defined. Either override the configure method or add an @Configuration annotation
    at org.springframework.util.Assert.state(Assert.java:392)
    at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:103)
    at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:68)
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5156)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

The Javadoc of SpringBootServletInitializer states:

Note that a WebApplicationInitializer is only needed if you are building a war file and
deploying it. If you prefer to run an embedded container then you won't need this at
all.

So we probably have to find a way how to not invoke SpringBootServletInitializer in case of a java -jar deployment. Do you have an idea how to do that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

unit testing - Embedded Tomcat 7 does not found ...
Hi, afaik javax.servlet.ServletContainerInitializer is located at tomcat-embed-core. · Issue is now solved. I change the parent ClassLoader of ...
Read more >
Apache Tomcat 8 (8.5.84) - Changelog
If upgrade is not possible, application code should cast to the internal Tomcat implementation classes. (markt); Fix: Switch Tomcat embedded ...
Read more >
Changelog - Apache Tomcat 9 (9.0.17)
Do not add CSRF nonce parameter and suppress Referer header for external links ... Update the Tomcat embedded API by allowing to set...
Read more >
Jetty : The Definitive Reference - Eclipse
While Jetty itself does not ship all of the Web Profile ... ServletContainerInitializer as shown in the embedded-jetty-jsp example on GitHub ...
Read more >
Fix list for IBM WebSphere Application Server V8.5
disabledAlgorithms property is not honored in a certain Java thin client scenario ... PI37687, IBM Embedded WebSphere Application Server is missing the jar ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found