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.

Document how to downgrade dependencies to use embedded Jetty 11

See original GitHub issue

In addition to downgrading the Servlet API to 5.0, we also need to cover the impact that this will have on testing. Framework’s Servlet-related mocks require Servlet 6.0 and will fail due to the absence of ServletConnection when run against the Servlet 5.0 API. Similarly, Jetty requires Servlet 5.0 and will fail due to the absence of HttpSessionContext when run against the Servlet 6.0 API. This leaves us with two arrangements that will work:

  1. Tests use the Servlet 6.0 API and avoid starting Jetty by only using a mock web environment
  2. Tests use the Servlet 5.0 API and avoid using Framework’s Servlet mocks by only using a full-blown web environment

If a mixture of web environments is required by an application’s tests, it can be done but it may require some structural changes to separate the two web environments. With Gradle this could be done with different source sets or separate modules. With Maven, I believe separate modules will always be required.

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, Nov 25, 2022

Yes, I believe that will work as your dependency management for jakarta.servlet-api is nearer to the root so it will take precedence over what’s in the imported spring-boot-dependencies.

1reaction
david-romerocommented, Nov 18, 2022

Hi @wilkinsona,

I’m facing this issue in a real application, not only in tests. Do you know how to fix it?

Starters added:

  • spring-boot-starter-web
    • exclude
      • spring-boot-starter-tomcat
  • spring-boot-starter-jetty
  • spring-boot-starter-amqp
  • spring-boot-starter-data-redis
  • spring-boot-starter-actuator
  • spring-boot-starter-validation
  • spring-boot-starter-json
  • spring-boot-starter-webflux
  • spring-boot-starter-data-jpa

Version: 3.0.0-RC2

Error trace:

java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 41 common frames omitted
Wrapped by: java.lang.NoClassDefFoundError: jakarta/servlet/http/HttpSessionContext
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	at org.eclipse.jetty.server.session.SessionHandler.<clinit>(SessionHandler.java:136)
	at org.eclipse.jetty.servlet.ServletContextHandler.newSessionHandler(ServletContextHandler.java:339)
	at org.eclipse.jetty.servlet.ServletContextHandler.getSessionHandler(ServletContextHandler.java:432)
	at org.eclipse.jetty.servlet.ServletContextHandler.relinkHandlers(ServletContextHandler.java:257)
	at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:180)
	at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:301)
	at org.eclipse.jetty.webapp.WebAppContext.<init>(WebAppContext.java:228)
	at org.springframework.boot.web.embedded.jetty.JettyEmbeddedWebAppContext.<init>(JettyEmbeddedWebAppContext.java:28)
	at org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory.getWebServer(JettyServletWebServerFactory.java:158)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:183)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161)
	... 21 common frames omitted
Wrapped by: org.springframework.context.ApplicationContextException: Unable to start web server
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:164)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:578)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
Read more comments on GitHub >

github_iconTop Results From Across the Web

spring boot - Springboot maven jetty version cannot be changed
For the property override to work, you need to declare spring-boot-starter-parent as your parent pom. (1) Without spring-boot as parent ...
Read more >
3.0.x Milestone - GitHub
Document how to downgrade dependencies to use embedded Jetty 11 type: documentation A documentation update. #33044 opened on Nov 7 by wilkinsona.
Read more >
Jetty11 Programming Guide | The Eclipse Foundation
The Eclipse Jetty Programming Guide targets developers who want to use the Eclipse Jetty libraries in their applications. The Eclipse Jetty ...
Read more >
Jetty Server Cookbook. Jetty Server Cookbook - KIPDF.COM
Adding dependencies for Embedded Jetty . ... 11 2.7 2.8 2.6.1. Changing the Jetty Port . ... Changing the Location and Name of...
Read more >
Spring Boot Reference Guide
Supporting an alternative embedded transaction manager ... Auto-configured Spring REST Docs tests; 40.3.11. Using ... Use Jetty instead of Tomcat; 70.12.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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