ClassNotFoundException: org.springframework.web.servlet.resource.LiteWebJarsResourceResolver in Springdoc
Problem Statement
When upgrading springdoc-openapi
from version 2.6.0 to 2.7.0 while using Spring Framework 6.1.x and Spring Boot 3.3.x, applications fail with a critical error:
ClassNotFoundException: org.springframework.web.servlet.resource.LiteWebJarsResourceResolver
This exception occurs during application startup and prevents the context from loading. The root cause is an incompatibility between framework versions and the springdoc library.
Understanding the Cause
The LiteWebJarsResourceResolver
class was introduced in Spring Framework 6.2. springdoc 2.7.0 depends on this new class, but:
- Spring Boot 3.3.x uses Spring Framework 6.1.x (which lacks this class)
- Spring Boot 3.4.x uses Spring Framework 6.2.x (which contains this class)
The version compatibility matrix is as follows:
Spring Framework | Spring Boot | Springdoc |
---|---|---|
6.2.x | 3.4.x | 2.7.x+ |
6.1.x | 3.3.x | 2.6.x |
Attempting to use springdoc 2.7.x with Spring Boot 3.3.x creates a dependency mismatch, resulting in the missing class exception.
Solutions
Option 1: Downgrade springdoc (Recommended for Spring Boot 3.3.x Users)
If you cannot upgrade Spring Boot, revert to the last compatible springdoc version.
Maven:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version> <!-- Compatible with SB 3.3.x -->
</dependency>
Gradle:
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0'
Option 2: Upgrade Spring Boot (Use with springdoc 2.7.x+)
To use springdoc 2.7.0+, upgrade your Spring Boot version to 3.4.x. First, update your Spring Boot parent POM:
Maven:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version> <!-- Minimum required version -->
</parent>
Then update springdoc:
Maven:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.7.0</version>
</dependency>
Gradle:
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0'
Verification Steps
After making changes:
- Run
mvn dependency:resolve
(Maven) orgradle dependencies
(Gradle) to ensure version consistency - Confirm you don't have mixed versions in your dependency tree
- Test application startup with
mvn spring-boot:run
orgradle bootRun
Compatibility Guidance
Always consult the official springdoc compatibility matrix before upgrading. Key principles:
- Spring Boot dictates compatibility: Springdoc versions align with Spring Boot releases
- Patch versions are intercompatible: You can use springdoc
2.6.x
with any Spring Boot3.3.x
version - Verify transitive dependencies: Use
mvn dependency:tree
to check for conflicting libraries
Conclusion
The ClassNotFoundException
for LiteWebJarsResourceResolver
occurs due to version mismatches between springdoc and Spring Boot. The safest solution is matching springdoc versions to your Spring Boot release:
- Spring Boot 3.3.x → springdoc 2.6.x
- Spring Boot 3.4.x+ → springdoc 2.7.x+
For existing Spring Boot 3.3.x projects, downgrading springdoc to 2.6.x is the most efficient fix without requiring framework upgrades.