我正在尝试将打开的 api 文档添加到我拥有的 springboot 基础 REST api 项目中。在 intelliJ IDE 本地运行或使用 gradlew run/bootRun 时,它工作正常
但是,当使用 gradlew shadow 插件“com.github.johnrengelman.shadow”将项目打包为胖 jar 并在命令行上运行时,java -jar build/libs/Application-0.0.1-SNAPSHOT-all.jar
它失败了ApplicationContextException
异常堆栈跟踪:
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
构建.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')
}
没有 openapi 依赖
implementation 'org.springdoc:springdoc-openapi-ui:1.5.12'
独立运行java -jar build/libs/Application-0.0.1-SNAPSHOT-all.jar
绝对正常。
open api 和 springboot 库之间是否存在一些依赖冲突?