首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >启动时的Spring引导Swagger UI异常

启动时的Spring引导Swagger UI异常
EN

Stack Overflow用户
提问于 2022-03-30 14:16:13
回答 1查看 3.5K关注 0票数 1

我正在尝试让Swagger在我的项目中工作,我正在跟踪这些医生,但是无论我尝试什么,我的应用程序都会立即崩溃,只有以下例外:

代码语言:javascript
运行
复制
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'swaggerWebMvcConfigurer' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Unsatisfied dependency expressed through method 'swaggerWebMvcConfigurer' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'indexPageTransformer' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Unsatisfied dependency expressed through method 'indexPageTransformer' parameter 3; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'swaggerWelcome' defined in class path resource [org/springdoc/webmvc/ui/SwaggerConfig.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springdoc.webmvc.ui.SwaggerWelcomeWebMvc] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@251a69d7]

我在Spring中使用Kotlin,这些是我的Gradle依赖关系:

代码语言:javascript
运行
复制
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-jooq")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-configuration-processor")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("com.braintreepayments.gateway:braintree-java:3.14.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.2")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.2")
implementation("org.apache.logging.log4j:log4j-layout-template-json")
implementation("org.springdoc:springdoc-openapi-kotlin:1.6.6")
implementation("org.springdoc:springdoc-openapi-ui:1.6.6")
implementation("org.jooq:jooq-meta")
implementation("org.jooq:jooq-kotlin")
implementation("org.jooq:jooq-codegen")
implementation("org.jooq:jooq-codegen-maven")
implementation("org.jooq:jooq-meta-extensions")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.6.10")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10")
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("com.github.ben-manes.caffeine:caffeine:3.0.5")
implementation("org.flywaydb:flyway-core:8.5.4")
implementation("org.postgresql:postgresql:42.3.3")

我在很多不同的组合中尝试过很多不同的包,但在启动时总是会抛出异常。

Gradle文件的插件部分:

代码语言:javascript
运行
复制
plugins {
    id("org.springframework.boot") version "3.0.0-SNAPSHOT"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    id("org.flywaydb.flyway") version "8.5.4"
    id("nu.studer.jooq") version "7.1.1"
    kotlin("jvm") version "1.6.20-RC"
    kotlin("plugin.spring") version "1.6.20-RC"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-08 18:32:42

Spring 3将使用Jakarta,而Spring 2仍然使用Java。此移动包括Servlet从javax.servletjakarta.servlet的命名空间更改。您的应用程序失败了,因为Springdoc1.x试图从旧的命名空间加载类,但是Springdoc 3只使用新的命名空间。

Springdoc发布了一个与Jakarta一起工作的里程碑版本,以及Springdoc 3的里程碑版本:https://github.com/springdoc/springdoc-openapi/issues/1284

在Java应用程序中,您可以替换

代码语言:javascript
运行
复制
implementation 'org.springdoc:springdoc-openapi-ui:1.6.6'

使用

代码语言:javascript
运行
复制
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0-M1'

这里还有一个官方的Maven示例:https://github.com/springdoc/springdoc-openapi-demos/tree/2.x/demo-spring-boot-3-webmvc

如果您只将启动器包含到Kotlin项目中,则

代码语言:javascript
运行
复制
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.0-M1")

这似乎很好,并生成Swagger用户界面。但是,目前似乎还没有相应的springdoc-openapi-kotlin里程碑版本。

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71678911

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档