I am trying to add open api documentation to springboot base REST api project that I have. It works fine when run locally inside intelliJ IDE or with gradlew run/bootRun
But when the project is packaged as a fat jar using gradlew shadow plugin 'com.github.johnrengelman.shadow' and run on command line as java -jar build/libs/Application-0.0.1-SNAPSHOT-all.jar
it fails with ApplicationContextException
Exception stacktrace:
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:205) ~[Application-0.0.1-SNAPSHOT-all.jar:?]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:177) ~[Application-0.0.1-SNAPSHOT-all.jar:?]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) ~[Application-0.0.1-SNAPSHOT-all.jar:?]
... 9 more
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'application'
id 'com.github.johnrengelman.shadow' version "6.0.0"
}
application {
mainClassName = 'com.example.Application'
executableDir = 'lib/'
}
dependencies {
implementation 'org.springdoc:springdoc-openapi-ui:1.5.12'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation files( "lib/$JarV2" )
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.3.3.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.4.2'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0'
implementation 'org.apache.logging.log4j:log4j-api:2.14.0'
implementation 'org.apache.logging.log4j:log4j-core:2.14.0'
implementation 'org.slf4j:jul-to-slf4j:1.7.30'
implementation 'commons-lang:commons-lang:2.6'
implementation "com.moandjiezana.toml:toml4j:0.7.2"
implementation "io.jsonwebtoken:jjwt-api:$jwtVersion"
runtimeOnly "io.jsonwebtoken:jjwt-impl:$jwtVersion"
runtimeOnly "io.jsonwebtoken:jjwt-jackson:$jwtVersion"
implementation 'com.auth0:java-jwt:3.18.1'
implementation 'com.auth0:jwks-rsa:0.19.0'
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
Without the openapi dependency
implementation 'org.springdoc:springdoc-openapi-ui:1.5.12'
standalone run java -jar build/libs/Application-0.0.1-SNAPSHOT-all.jar
works absolutely fine.
Is there some dependency conflict between open api and springboot libs ?