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

Embedded Jetty 11 failed to start on Framework 6.0.2 / Boot 3.0.0 because of Servlet API 6.0 is used #29585

Closed
vladimirfx opened this issue Nov 26, 2022 · 3 comments
Labels
for: external-project Needs a fix in external project status: invalid An issue that we don't feel is valid

Comments

@vladimirfx
Copy link

spring-boot-starter-web with spring-boot-starter-jetty is used. Another environment does not matter.

Reproducer:
boot3-jetty11-error.zip

Workaround (Gradle):

runtimeOnly("org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2")

Error log:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.0)

2022-11-26T13:35:34.558Z  INFO 1 --- [           main] r.f.m.b.ApplicationKt                    : Starting ApplicationKt using Java 17.0.5 with PID 1 (/app/classes started by nobody in /)
2022-11-26T13:35:34.559Z  INFO 1 --- [           main] r.f.m.b.ApplicationKt                    : No active profile set, falling back to 1 default profile: "default"
2022-11-26T13:35:36.250Z  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-11-26T13:35:36.318Z  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 58 ms. Found 0 JPA repository interfaces.
2022-11-26T13:35:37.085Z  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server
2022-11-26T13:35:37.130Z  INFO 1 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2022-11-26T13:35:37.209Z ERROR 1 --- [           main] o.s.b.SpringApplication                  : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578) ~[spring-context-6.0.2.jar:6.0.2]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[spring-boot-3.0.0.jar:3.0.0]
  at ru.fcb.mobilefieldcollection.backend.ApplicationKt.main(Application.kt:57) ~[classes/:?]
Caused by: java.lang.NoClassDefFoundError: jakarta/servlet/http/HttpSessionContext
  at org.eclipse.jetty.servlet.ServletContextHandler.newSessionHandler(ServletContextHandler.java:339) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.servlet.ServletContextHandler.getSessionHandler(ServletContextHandler.java:432) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.servlet.ServletContextHandler.relinkHandlers(ServletContextHandler.java:257) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:180) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:301) ~[jetty-webapp-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:228) ~[jetty-webapp-11.0.12.jar:11.0.12]
  at org.springframework.boot.web.embedded.jetty.JettyEmbeddedWebAppContext.<init>(JettyEmbeddedWebAppContext.java:28) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:158) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-3.0.0.jar:3.0.0]
  ... 8 more
Caused by: java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext
  at jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
  at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
  at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
  at org.eclipse.jetty.servlet.ServletContextHandler.newSessionHandler(ServletContextHandler.java:339) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.servlet.ServletContextHandler.getSessionHandler(ServletContextHandler.java:432) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.servlet.ServletContextHandler.relinkHandlers(ServletContextHandler.java:257) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:180) ~[jetty-servlet-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:301) ~[jetty-webapp-11.0.12.jar:11.0.12]
  at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:228) ~[jetty-webapp-11.0.12.jar:11.0.12]
  at org.springframework.boot.web.embedded.jetty.JettyEmbeddedWebAppContext.<init>(JettyEmbeddedWebAppContext.java:28) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:158) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183) ~[spring-boot-3.0.0.jar:3.0.0]
  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-3.0.0.jar:3.0.0]
  ... 8 more
[
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 26, 2022
@jhoeller
Copy link
Contributor

jhoeller commented Nov 26, 2022

I'm afraid this is a Spring Boot issue rather than a Spring Framework issue since the core framework does not manage the presence of specific API jars in the application classpath. It rather just happens to compile against certain API versions itself but leaves the concrete choice up to the application at runtime.

Spring Boot 3.0 is meant to choose Servlet 6.0 for Tomcat and Undertow (matching their latest versions) but downgrade to Servlet 5.0 for Jetty (where no Servlet 6.0 support is available for production yet). @wilkinsona for your awareness, I suppose the Servlet API downgrade for Jetty 11 is somehow incomplete?

In any case, please create this issue for Spring Boot instead: https://github.com/spring-projects/spring-boot/issues

@vladimirfx
Copy link
Author

Done: spring-projects/spring-boot#33373

@vladimirfx vladimirfx closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2022
@bclozel bclozel added status: invalid An issue that we don't feel is valid for: external-project Needs a fix in external project and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 26, 2022
@wilkinsona
Copy link
Member

I suppose the Servlet API downgrade for Jetty 11 is somehow incomplete?

Unfortunately, it isn't possible for Boot to perform this downgrade automatically. It has to be done manually as briefly mentioned in Boot 30's migration guide. spring-projects/spring-boot#33044 will expand on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project Needs a fix in external project status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

5 participants