SpringDocWebFluxConfiguration throws NoClassDefFoundError: javax/servlet/ServletException
See original GitHub issueDescribe the bug
We’re trying to migrate JHipster to use Springdoc instead of Springfox.
https://github.com/jhipster/jhipster-bom/pull/556
In a Spring WebFlux application, I have the following dependencies:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-core</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-data-rest</artifactId>
</dependency>
When the app starts, I get the following error:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'openApiResource' defined in class path resource
[org/springdoc/webflux/core/SpringDocWebFluxConfiguration.class]: Unsatisfied dependency expressed through
method 'openApiResource' parameter 2; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'responseBuilder'
defined in class path resource [org/springdoc/webflux/core/SpringDocWebFluxConfiguration.class]: Bean
instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springdoc.core.GenericResponseService]: Factory method 'responseBuilder' threw
exception; nested exception is java.lang.NoClassDefFoundError: javax/servlet/ServletException
Another strange thing that happens with these two dependencies. A new webflux + MongoDB app fails with the following when running mvn verify:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springdoc.core.GenericResponseService]: Factory method 'responseBuilder' threw exception; nested
exception is java.lang.NoClassDefFoundError: Could not initialize class
org.springdoc.core.GenericResponseService
However, if I change replace both dependencies with springdoc-openapi-webflux-ui, all tests pass.
To Reproduce
Steps to reproduce the behavior:
- What version of spring-boot you are using? 2.5.7
- What modules and versions of springdoc-openapi are you using? 1.5.13
- What is the actual and the expected result using OpenAPI Description (yml or json)?
- Provide with a sample code (HelloController) or Test that reproduces the problem
I can provide steps to reproduce, but it’s kinda complicated. Here’s an attempt:
git clone -b springdocs git@github.com:mshima/jhipster-bom.git
cd jhipster-bom
./mvnw install -Dgpg.skip=true
cd ..
git clone -b skip_ci-doc git@github.com:mshima/generator-jhipster.git
cd generator-jhipster
npm link
Then, create a new JHipster project (for example, in your ~/Downloads directory):
mkdir webflux-mongodb
cd webflux-mongodb
Create a .yo-rc.json file in this directory with the following contents:
{
"generator-jhipster": {
"applicationType": "monolith",
"reactive": true,
"baseName": "sampleWebfluxMongodb",
"packageName": "tech.jhipster.sample",
"packageFolder": "tech/jhipster/sample",
"authenticationType": "jwt",
"cacheProvider": "no",
"enableHibernateCache": false,
"websocket": false,
"databaseType": "mongodb",
"devDatabaseType": "mongodb",
"prodDatabaseType": "mongodb",
"searchEngine": false,
"buildTool": "maven",
"enableTranslation": true,
"nativeLanguage": "en",
"languages": ["en", "fr"],
"testFrameworks": ["gatling", "cypress"],
"serverPort": "8080",
"jhiPrefix": "jhi",
"clientPackageManager": "npm",
"clientFramework": "angularX",
"creationTimestamp": 1596513172471,
"jwtSecretKey": "ZjY4MTM4YjI5YzMwZjhjYjI2OTNkNTRjMWQ5Y2Q0Y2YwOWNmZTE2NzRmYzU3NTMwM2NjOTE3MTllOTM3MWRkMzcyYTljMjVmNmQ0Y2MxOTUzODc0MDhhMTlkMDIxMzI2YzQzZDM2ZDE3MmQ3NjVkODk3OTVmYzljYTQyZDNmMTQ=",
"jhipsterVersion": "7.4.0",
"skipClient": false,
"skipServer": false,
"skipUserManagement": false,
"skipCheckLengthOfIdentifier": false,
"skipFakeData": false,
"entitySuffix": "",
"dtoSuffix": "DTO",
"blueprints": [],
"otherModules": [],
"pages": [],
"devServerPort": 4200,
"clientTheme": "none",
"clientThemeVariant": "",
"withAdminUi": true,
"serviceDiscoveryType": false,
"enableGradleEnterprise": false
}
}
Then, run jhipster.
Once the app is finished, run ./mvnw verify to see the test failures.
To start the app:
docker-compose -f src/main/docker/mongodb.yml up -d
./mvnw
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (11 by maintainers)

Top Related StackOverflow Question
@bnasslahsen just an update. Your solution worked, fixed the problem. Is there is a way to detect this conflict?
Maybe the pageable config could be moved to a config in common package, so we can import it: https://github.com/springdoc/springdoc-openapi/blob/6c86b61cd666e7de1cee926ac34c47243f6ff741/springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/SpringDocDataRestConfiguration.java#L88-L104
There is a conditional at hateos package: https://github.com/springdoc/springdoc-openapi/blob/6c86b61cd666e7de1cee926ac34c47243f6ff741/springdoc-openapi-hateoas/src/main/java/org/springdoc/hateoas/SpringDocHateoasConfiguration.java#L55 but not at data-rest package: https://github.com/springdoc/springdoc-openapi/blob/6c86b61cd666e7de1cee926ac34c47243f6ff741/springdoc-openapi-data-rest/src/main/java/org/springdoc/data/rest/SpringDocDataRestConfiguration.java#L127-L131
I really appreciate your help. I think this bug can be closed now.
@mshima,
Exactly, you are right! When using groups, the
OpenAPIServicescope should bePROTOTYPE. This a sample code how it’s implemented inspringdoc-openapi:https://github.com/springdoc/springdoc-openapi/blob/cfe86b6554bd46e2e4b74f686d1e9837fee65f29/springdoc-openapi-common/src/main/java/org/springdoc/core/SpringdocBeanFactoryConfigurer.java#L86-L92
This is not working in your case, as you have declared in
JHipsterSpringDocAutoConfigurationa conflicting condition:@AutoConfigureBefore(SpringDocConfiguration.class)vs@Import(SpringDocConfiguration.class). This causes theCacheOrGroupedOpenApiConditionnot to be verified.I believe the straight forward solution will be as follow (The less of
springdoc-openapiBeans overriding/duplication):As you can see, i have also not loaded
JHipsterSpringDocWebFluxConfigurationorJHipsterSpringDocMvcConfigurationas the loading ofMultipleOpenApiWebMvcResourceandMultipleOpenApiWebFluxResourceis already done by thesprindoc-openapistarter.Of course, you can also remove
springdoc.cache.disabled = true, from the generatedapplication.yml.Don’t hesitate to let me know, if these instructions help you solve the cache issue.